byte.billionaire Posted February 16, 2007 Share Posted February 16, 2007 Hi All, I want to execute an external program and I have the following program. <?php $cmd = "sudo -u root -S ifconfig eth0 0.0.0.0 down"; exec($cmd); ?> When running in terminal mode... no problem at all. When running in Apache/PhP mode...... PROBLEM.... I have also this line in the the /etc/sudoers apache ALL = NOPASSWD: ALL Please help!!! Thanks. Link to comment https://forums.phpfreaks.com/topic/38732-php-exec-problem/ Share on other sites More sharing options...
btherl Posted February 16, 2007 Share Posted February 16, 2007 It could be to do with paths. Try giving the full path for sudo and ifconfig Apart from that, try printing out the return value from exec(), and/or adding the optional second argument to exec() (which records the entire output). Maybe there's some hints in there. Link to comment https://forums.phpfreaks.com/topic/38732-php-exec-problem/#findComment-186103 Share on other sites More sharing options...
byte.billionaire Posted February 16, 2007 Author Share Posted February 16, 2007 I have changed the code to this.... <?php $data = array(); $cmd = "sudo -u root -S /sbin/ifconfig eth0 0.0.0.0 down"; exec($cmd, $data, $ret); echo "<pre>"; if ($ret == 0) // check status code. if successful foreach ($data as $line) echo "$line \n"; else echo "Cannot execute $prgfile for some reason"; // if unsuccessful display error echo "</pre>"; ?> However, still could not execute it probably....Any other recommendations??? Link to comment https://forums.phpfreaks.com/topic/38732-php-exec-problem/#findComment-186113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.