Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running system command from php

Status
Not open for further replies.

proggybilly

Programmer
Apr 30, 2008
110
US
I am trying to put together a page that displays different information about the system. One of the commands I want to run is hdparm so that I can gather the hard drive serial number. My code looks like this:

Code:
$hd = system("hdparm -I /dev/sda");
echo $hd;

But I get nothing when I pull up the page to display.

Any help is greatly appreciated
 
ok. I assume that you have edited sudoers with visudo?

and that the edit was made using sudo as root?

I think that the correct line in sudoers should be as I posted (save for the change in user name)

Code:
asterisk    ALL[red]=(ALL)[/red] NOPASSWD: /usr/bin/php -f /var/[URL unfurl="true"]www/html/ivrconfig/pwd.php[/URL]

I notice aswell that you are looking at getting hdparm for /dev/[red]sda[/red] my code is querying for /dev/[red]hda[/red]. if you are sure of your device name, then you should change my code accordingly.
 
Ok, making some progress I think. I still get

Array
(
)

If I run on the command line as root, php test.php, it displays the array accordingly.

If I su asterisk and run php test.php, i get:
HDIO_DRIVE_CMD(identify) failed: Permission denied
<pre>Array
(
[0] =>
[1] => /dev/sda:
)

So making progress for sure. At least I know your scripts work as root. Now to get it working accordingly as asterisk.
 
Correction, I changed my hdparm -I to hdparm -i and now it works! Thank you so very much!
 
Ok so I copy my files from the development server to the production server. i add the sudoers line accordingly. If I rung on command line, the hdparm stuff works, however it will not display in the brower.. Sheesh.... If it's not one thing.
 
Then I suspect your server is not running as asterisk. try calling phpinfo to check the user perms
 
Oh it was running asterisk. For some reason, I had to do a service httpd restart and that fixed it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top