Shutdown and Reboot Linux System via php script
How to shutdown and reboot the linux system via php script. We have used more linux commands in php exec, shell_exec and system functions. But the commands are not working properly in php script. The commands are working in linux terminal. Please help me.
|
Quote:
|
Shutdown and Reboot in linux system
How to shutdown and reboot the linux system via php script. We have used more linux commands in php exec, shell_exec and system functions. But the commands are not working properly in php script. The commands are working in linux terminal.
I m using Linux Fedora 7.0. I used more shell commands via php. But no errors display on the screen. Display a blank page only. But the display_errors option is enabled in my system and error_reporting also enabled(E_ALL). I dont know the exact problem. But the shell commands are working in linux terminal. My system have full administrator permission. php1.php <?php shell_exec("/usr/bin/reboot"); exec("/usr/bin/reboot"); system("/usr/bin/reboot"); ?> php2.php <?php shell_exec("/usr/sbin/reboot"); exec("/usr/sbin/reboot"); system("/usr/sbin/reboot"); ?> php3.php <?php shell_exec("shutdown"); exec("shutdown"); system("shutdown"); ?> php4.php <?php shell_exec("shutdown -r"); exec("shutdown -r"); system("shutdown -r"); ?> ..... ?> |
Quote:
Before anyone can give you any help, you're going to have to explain the problem. My initial guess is that you're running this 'script' as a root-equivalent user from the terminal, which has rights to run those commands. You don't say whether or not you're doing this from cron, via an AT job, or how, exactly you're running it. Also, Fedora 7 is very old...Fedora 10 is the latest. |
Shutdown and Reboot in linux system
How to shutdown and reboot the linux system via php script. We have used more linux commands in php exec, shell_exec and system functions. But the commands are not working properly in php script. The commands are working in linux terminal.
I m using Linux Fedora 7.0. I used more shell commands via php. But no errors display on the screen. Display a blank page only. But the display_errors option is enabled in my system and error_reporting also enabled(E_ALL). I dont know the exact problem. But the shell commands are working in linux terminal. My system have full administrator permission. php1.php <?php shell_exec("/usr/bin/reboot"); exec("/usr/bin/reboot"); system("/usr/bin/reboot"); ?> php2.php <?php shell_exec("/usr/sbin/reboot"); exec("/usr/sbin/reboot"); system("/usr/sbin/reboot"); ?> php3.php <?php shell_exec("shutdown"); exec("shutdown"); system("shutdown"); ?> php4.php <?php shell_exec("shutdown -r"); exec("shutdown -r"); system("shutdown -r"); ?> ..... ?> and more scripts. Really thanks to TB0ne. Thanks for your reply. My system have all administrator privileges. My sytem have root privilege. Fedora 7.0 is support to execute linux commands like reboot ... commands in terminal. Boss all linux os with all versions are support to execute all types of linux commands in terminal. My system also support to execute linux commands like reboot commands are working fine. But the system oriented commands are not support to execute via php. The "ls" command is working fine via php. I want to develop one demo for handling system and apache, mysql service areas. For example shutdown, reboot, apache-start,stop,restart, mysql-start,stop, restart options. Do u have any reference script or site. Pls sent to me. C/C++ files also used. But no response. This demo work is not based cron or AT or any other. Just for demo purpose only. I want to teach this commands and show a demo to my students. |
Try using root
<?php $command = "cat $pass | su -c 'shutdown -r now'"; $output = array(); try{ echo shell_exec($command); exec($command, $output); system($command, $output); }Catch(Exception e){ print "Unable to shutdown system...\n"; } foreach ($output as $line) { print "$line<br>"; } ?> This way you can store your root password in a config file, and your students can still understand the code. Your students might understand something that wouldn't reboot the machine.. http://www.devguru.com/technologies/php/6010.asp |
The shutdown and reboot command do not run from /usr/sbin but from /sbin/reboot.
You should need to change the complete path of the command from /usr/sbin/reboot to /sbin/reboot. If you are not sure about it check with which command. |
Quote:
A simple way to do it with out entering root passwords in php scripts would be to make a root crontab, take about a minute or two max to reboot the server. root crontab Code:
* * * * * /usr/local/sbin/checkreboot.sh Code:
#!/bin/bash Code:
<?php If you wanted it to be almost immediate you could make the script run in a loop if its not already running and testing for the file each iteration and sleeping for 1 at the end to prevent it from being to much of a drain on the system resources. Also if memory serves me you could do the same thing via a snmp daemon and just issue an snmp call to the daemon to reboot the system. |
All times are GMT -5. The time now is 11:19 AM. |