PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > How to pass variable to operating system.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to pass variable to operating system.

Réponse
 
LinkBack Outils de la discussion
Vieux 09/10/2007, 19h15   #1 (permalink)
Henk Oegema
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to pass variable to operating system.

In the php script below I use 3 variables:
1. &day
2. $hour
3. $minute.


Filename:/opt/lampp/htdocs/uptime/uptime.php

<?php

################################################## #########################
# #
# Copyright © http://www.4web.net/ #
# Neither http://www.4web.net/ nor its members accept any #
# responsibility, either expressed or implied, for any damage caused by #
# using this script or the misuse of this script. #
# #
# Adapted for Asterisk PBX by Henk Oegema #
# #
# INSTRUCTIONS #
# #
# 1) Copy this code to an editor such as Notepad and save it with a #
# .php extension. #
# 2) FTP this file to a folder on your site in ASCII mode #
# 3) Call up this file in your web browser to see your server's uptime #
# #
################################################## #########################

$data = shell_exec('uptime');
$uptime = explode(' up ', $data);
$uptime = explode(',', $uptime[1]);
$uptime = $uptime[0].' ' .$uptime[1];


$days = explode(' ', $uptime);
$hours = explode(':', $days[3]);

$day = $days[0];
$hour = $hours[0];
$minute = $hours[1];

?>

Question: How to I pass those 3 variables from the script, to 3 variables in
Linux (Debian).

Something like:
asterisk:~# day=${CURL(http://localhost/uptime/uptime.php)} (?????)
asterisk:~# hour=...........
asterisk:~# minute=.........


  Réponse avec citation
Vieux 09/10/2007, 19h49   #2 (permalink)
J.O. Aho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to pass variable to operating system.

Henk Oegema wrote:

> Question: How to I pass those 3 variables from the script, to 3 variables in
> Linux (Debian).
>
> Something like:
> asterisk:~# day=${CURL(http://localhost/uptime/uptime.php)} (?????)
> asterisk:~# hour=...........
> asterisk:~# minute=.........


You would need to use

export day=`php /path/to/yout/file/uptime.php`

if you use it this way, you need to make the script to take arguments, so that
you can get the day, hour and minute alone. Don't forget to echo about the value.

Otherwise you can use a shell script with awk that can read out the values and
then set each variable, but then you could skip using php, as you get the
uptime from uptime command directly.


--

//Aho
  Réponse avec citation
Vieux 09/10/2007, 22h02   #3 (permalink)
Henk Oegema
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to pass variable to operating system.

>J.O. Aho wrote:
Tnx Aho for answering.
> Henk Oegema wrote:
>
>
> You would need to use
>
> export day=`php /path/to/yout/file/uptime.php`
>
> if you use it this way, you need to make the script to take arguments, so
> that
> you can get the day, hour and minute alone. Don't forget to echo about
> the value.

Can you please be a little bit more specific. It's not quit clear to me.
Why (and how) must the script take arguments?
The values of the 3 variables are already known to the script.
I only need to pass them to the operating system.
>
> Otherwise you can use a shell script with awk that can read out the values
> and then set each variable, but then you could skip using php, as you get
> the uptime from uptime command directly.

You right, this is also a possibility.
>
>

Rgds
Henk

  Réponse avec citation
Vieux 10/10/2007, 03h42   #4 (permalink)
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to pass variable to operating system.

Henk Oegema wrote:
>> J.O. Aho wrote:

> Tnx Aho for answering.
>> Henk Oegema wrote:
>>
>>
>> You would need to use
>>
>> export day=`php /path/to/yout/file/uptime.php`
>>
>> if you use it this way, you need to make the script to take arguments, so
>> that
>> you can get the day, hour and minute alone. Don't forget to echo about
>> the value.

> Can you please be a little bit more specific. It's not quit clear to me.
> Why (and how) must the script take arguments?
> The values of the 3 variables are already known to the script.
> I only need to pass them to the operating system.
>> Otherwise you can use a shell script with awk that can read out the values
>> and then set each variable, but then you could skip using php, as you get
>> the uptime from uptime command directly.

> You right, this is also a possibility.
>>

> Rgds
> Henk
>


But what's the operating system going to do with them?

The operating system doesn't take parameters. Rather, you run a program
(even if it is the shell) which does something with parameters.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
Vieux 10/10/2007, 05h33   #5 (permalink)
J.O. Aho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to pass variable to operating system.

Henk Oegema wrote:
>> J.O. Aho wrote:
>> Henk Oegema wrote:
>>
>>
>> You would need to use
>>
>> export day=`php /path/to/yout/file/uptime.php`
>>
>> if you use it this way, you need to make the script to take arguments, so
>> that
>> you can get the day, hour and minute alone. Don't forget to echo about
>> the value.

> Can you please be a little bit more specific. It's not quit clear to me.
> Why (and how) must the script take arguments?
> The values of the 3 variables are already known to the script.


As you can't export three shell variables at the same time, you require to set
them one at the time. If you still want to output all three at the same time
in the php script, then you need to use awk or another string manipulating
command and in which case it's less overhead to make a shell script that does
all itself.



--

//Aho
  Réponse avec citation
Vieux 10/10/2007, 05h43   #6 (permalink)
J.O. Aho
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to pass variable to operating system.

Jerry Stuckle wrote:
> Henk Oegema wrote:
>>> J.O. Aho wrote:

>> Tnx Aho for answering.
>>> Henk Oegema wrote:
>>>
>>>
>>> You would need to use
>>>
>>> export day=`php /path/to/yout/file/uptime.php`
>>>
>>> if you use it this way, you need to make the script to take
>>> arguments, so
>>> that
>>> you can get the day, hour and minute alone. Don't forget to echo about
>>> the value.

>> Can you please be a little bit more specific. It's not quit clear to me.
>> Why (and how) must the script take arguments? The values of the 3
>> variables are already known to the script.
>> I only need to pass them to the operating system.
>>> Otherwise you can use a shell script with awk that can read out the
>>> values
>>> and then set each variable, but then you could skip using php, as you
>>> get
>>> the uptime from uptime command directly.

>> You right, this is also a possibility.

> But what's the operating system going to do with them?
> The operating system doesn't take parameters. Rather, you run a program
> (even if it is the shell) which does something with parameters.


The values are already "stored" in the OS in question, it do have track of
it's own lifespan, but of course not stored as a variable that is accessible
by the shell.

if the OP exports the value, they will only be in the shell he currently works
in, switching to another virtual console will just make that the variables in
question are empty as they never been set.
Of course it would be possible to set the values in ~/.bashrc, but then the
values will be different for each shell.

Not sure if the OP really thought about what he wants to do...

--

//Aho
  Réponse avec citation
Vieux 10/10/2007, 07h54   #7 (permalink)
Henk Oegema
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to pass variable to operating system.

>
> But what's the operating system going to do with them?
>
> The operating system doesn't take parameters. Rather, you run a program
> (even if it is the shell) which does something with parameters.

Yes jerry, you are right. That's exactly what I want.
Sorry for my confusion.

I want to pass the values of the three variables in the php script to my PBX
dial plan (Asterisk):

exten => 3014,1,Playback(wait-moment)
exten => 3014,n,Set(days=...) <----Here I need the value of $days from the
php script.
exten => 3014,n,Set(hours=..) <----Here I need the value of $hour from the
php script.
exten => 3014,n,Set(minutes=..)<---Here I need the value of $minutes from
the php script.
exten => 3014,n,System(echo "the server uptime is ${days} days and ${hours}
hours and ${minutes} minutes" | /usr/bin/text2wave -scale 1.5 -F
8000 -o /tmp/uptime.wav)
exten => 3014,n,Playback(/tmp/uptime)
exten => 3014,n,System(rm /tmp/uptime.wav)
exten => 3014,n,Playback(goodbye)
exten => 3014,n,Hangup()
>



I use something similar to get my account balance from the web:

exten => 3000,1,Answer
exten => 3000,n,Playback(astcc-account-balance-is)
exten =>
3000,n,Set(status=${CURL(http://localhost/credit/credit_dialnow.php)})
<----HERE I GET MY ACCOUNT BALANCE.
exten => 3000,n,SayDigits(${status})
exten => 3000,n,Playback(vm-goodbye)
exten => 3000,n,Hangup()

  Réponse avec citation
Vieux 10/10/2007, 07h59   #8 (permalink)
Henk Oegema
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to pass variable to operating system.

J.O. Aho wrote:

> Henk Oegema wrote:
>>> J.O. Aho wrote:
>>> Henk Oegema wrote:
>>>
>>>
>>> You would need to use
>>>
>>> export day=`php /path/to/yout/file/uptime.php`
>>>
>>> if you use it this way, you need to make the script to take arguments,
>>> so that
>>> you can get the day, hour and minute alone. Don't forget to echo about
>>> the value.

>> Can you please be a little bit more specific. It's not quit clear to me.
>> Why (and how) must the script take arguments?
>> The values of the 3 variables are already known to the script.

>
> As you can't export three shell variables at the same time, you require to
> set them one at the time. If you still want to output all three at the
> same time in the php script, then you need to use awk or another string
> manipulating command and in which case it's less overhead to make a shell
> script that does all itself.
>
>
>

Please Aho see my reply to Jerry.
With awk I can get my dial plan working.

But I want to learn how to do it with a php script.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h46.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16107 seconds with 16 queries