Reboot From PHP Page


<?php
	//----- DO THE REBOOT -----
		//THIS SUDO COMMAND NEEDS TO BE AUTHORISED FOR APACHE TO USE IT IN THE FILE: sudo nano /etc/sudoers
		//	# Special for this system - let apache run exes we use in the web interface
		//	www-data ALL=NOPASSWD: /sbin/reboot
	echo '<pre>';
	system("(sleep 2 ; sudo /sbin/reboot ) > /dev/null 2>&1 & echo $!");
	echo '</pre>';
?>

The sleep causes a 2 second delay before its actions.

The "> /dev/null 2>&1 & echo $!" causes the system command to return immediately and for the command to be issued in the background, allowing the page to load before the reboot actually occurs.

 

Comments

  1. Chris

    5 years ago

    Remove the ‘echo’ in /dev/null 2>&1 & echo $!”);

    Otherwise the process # is displayed on the webpage.