|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 (permalink) |
|
Messages: n/a
Hébergeur: |
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=......... |
|
|
|
#2 (permalink) |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 (permalink) |
|
Messages: n/a
Hébergeur: |
>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 |
|
|
|
#4 (permalink) |
|
Messages: n/a
Hébergeur: |
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 ================== |
|
|
|
#5 (permalink) |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 (permalink) |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#7 (permalink) |
|
Messages: n/a
Hébergeur: |
>
> 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() |
|
|
|
#8 (permalink) |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|