| | |
Running Linux Commands through PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2008
Posts: 21
Reputation:
Solved Threads: 0
Hey folks,
I am fairly new in the field of PHP. I have to prepare a module that will show the CPU utilization, current processes, memory utilization and disk quota of a remote system when asked on a PHP page. I am clueless about how to proceed in this matter. My seniors asked me to do scripting in PHP through which I must run Linux Commands and then parse the result I got and display it in a web browser. Please help me out and guide me how to proceed in this matter.
Thanks
I am fairly new in the field of PHP. I have to prepare a module that will show the CPU utilization, current processes, memory utilization and disk quota of a remote system when asked on a PHP page. I am clueless about how to proceed in this matter. My seniors asked me to do scripting in PHP through which I must run Linux Commands and then parse the result I got and display it in a web browser. Please help me out and guide me how to proceed in this matter.
Thanks
Commitment is what transforms a promise into reality. It is the words that speak boldly of your intentions. And the actions which speak louder than the words. It is making the time when there is none. Commitment is the stuff character is made of; the power to change the face of things. It is the daily triumph of integrity over skepticism.
You can execute linux commands within a php script - all you have to do is put the command line in backticks (`).
And also concentrate on exec() , this and shell_exec()..
And also concentrate on exec() , this and shell_exec()..
Last edited by Shanti Chepuru; Sep 25th, 2008 at 2:20 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
•
•
Join Date: Jun 2008
Posts: 21
Reputation:
Solved Threads: 0
Thanks Shanti but would you be a bit elaborate about how could I log in to a remote server. I had visited php.net earlier but the first and foremost problem for me is to log into the remote system. Suppose the username is "abcde", password is "wxyz" and IP address is 100.100.100.100. Please tell me how to first log into this system using these parameters. Any sort of help would be much appreciated.
Thanks Again
Gaurav
Thanks Again
Gaurav
Commitment is what transforms a promise into reality. It is the words that speak boldly of your intentions. And the actions which speak louder than the words. It is making the time when there is none. Commitment is the stuff character is made of; the power to change the face of things. It is the daily triumph of integrity over skepticism.
•
•
•
•
Thanks Shanti but would you be a bit elaborate about how could I log in to a remote server. I had visited php.net earlier but the first and foremost problem for me is to log into the remote system. Suppose the username is "abcde", password is "wxyz" and IP address is 100.100.100.100. Please tell me how to first log into this system using these parameters. Any sort of help would be much appreciated.
Thanks Again
Gaurav
eg:
http://remote-sever.com/memory-and-disk-quota.php
php Syntax (Toggle Plain Text)
<?php $results = exec('your command'); echo $results; ?>
Then from your local machine query the remote system over HTTP:
php Syntax (Toggle Plain Text)
<?php $results = file_get_contents(' http://remote-sever.com/memory-and-disk-quota.php'); echo $results; ?>
You can also build authentication into the remote machine, or use basic auth, etc.
eg: basic auth
PHP Syntax (Toggle Plain Text)
<?php $results = file_get_contents(' http://user:pass@remote-sever.com/memory-and-disk-quota.php'); echo $results; ?>
This way, you don't ever send arbitrary code to the remote system, and limit the code execution to that hardcoded into your PHP file.
If you really need to pass arbitrary commands to the remote system for some reason, you may want to implement the SSH protocol. In this way, your PHP script will act as an SSH client, that will log into the SSH server on the remote system, execute commands and read the response.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Aug 2005
Posts: 4
Reputation:
Solved Threads: 0
Hi,
Pls tell me how to code this shell command in PHP
( echo "RGBA32 88 31 20 25 0 1" ; cat /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.rgba ) > /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.fifo &
I tried above but it seems not working no output.
Pls tell me how to code this shell command in PHP
( echo "RGBA32 88 31 20 25 0 1" ; cat /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.rgba ) > /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.fifo &
•
•
•
•
<?php
echo shell_exec('( echo "RGBA32 197 32 120 205 0 1" ; cat /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.rgba ) > /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.fifo &');
?>
•
•
•
•
Hi,
Pls tell me how to code this shell command in PHP
( echo "RGBA32 88 31 20 25 0 1" ; cat /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.rgba ) > /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.fifo &
I tried above but it seems not working no output.
There will be no output from those set of commands. All output from the first and seconds are sent to: /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.fifo
so if you want to see if it works, view the contents of /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.fifo
eg:
PHP Syntax (Toggle Plain Text)
cat /var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.fifo
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Aug 2005
Posts: 4
Reputation:
Solved Threads: 0
ok Thank you next thing is this SSH command its working fine on the command prompt(file converting). but not working in PHP. ( the file not converting)
mencoder -oac copy -vf bmovl=0:0:mylogo.fifo -ovc raw -o t2.mpg t1.mpg
what do i have to do to fix this ?
mencoder -oac copy -vf bmovl=0:0:mylogo.fifo -ovc raw -o t2.mpg t1.mpg
•
•
•
•
<?php
echo shell_exec('/usr/bin/mencoder -oac copy -vf bmovl=0:0:/var/www/vhosts/lankaclipstv.com/httpdocs/mylogo.fifo -ovc raw -o /var/www/vhosts/lankaclipstv.com/httpdocs/t2.mpg /var/www/vhosts/lankaclipstv.com/httpdocs/t1.mpg');
?>
![]() |
Similar Threads
- How to install a Debian LAMP Server (PHP)
- Apache (Linux Servers and Apache)
- HOW TO: Start your own home server [both Windows & Linux] (Linux Servers and Apache)
- Changing permission for www/html directory (Window and Desktop Managers)
- Suse 9.0 and USR5610B (*nix Hardware Configuration)
Other Threads in the PHP Forum
- Previous Thread: Minor Problem
- Next Thread: php4
| Thread Tools | Search this Thread |
# 5.2.10 ajax apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date display dissertation dynamic echo echo$_get[x]changingitintovariable... email error file files folder form forms function functions google href htaccess html image images include insert integration ip java javascript joomla ldap legislation limit link local login loop mail memberships menu mlm multiple multipletables mysql mysqlquery oop open paypal pdf persist php problem query radio random recursion regex remote rss script search server sessions sms soap sockets source space spam sql syntax system table tutorial update upload url validator variable video web xml youtube






