I am wondering how I could possibly input the values for option (e.g -r), time (e.g now) and message (e.g Shutting down), I have tried:
system("shutdown " . $option . "-t " . $time . " " . $message);
and that didn't work? (I am doing it via PHP, also.)
This is the code that I have so far in shutdown.php:
<?php
$option = $_POST['option'];
$time = $_POST['time'];
$message = $_POST['message];
?>
I am using Apache 2 by the way.
-
The Pi is a general Linux box and is nothing special in this regard. Why not just have a shutdown script on the Pi (such as sudo shutdown -hP now) and just invoke the script?joan– joan2015年04月08日 10:43:05 +00:00Commented Apr 8, 2015 at 10:43
-
I'm not exactly a Linux genius :P , you might have to explain how I would go about doing such a thingConnor– Connor2015年04月08日 10:43:59 +00:00Commented Apr 8, 2015 at 10:43
-
Login to the Pi (user pi presumably). Enter nano off. Add two lines, the first with #!/bin/bash, the second with sudo shutdown -hP now. Make it executable, chmod +x off. In your PHP use system("/home/pi/off");joan– joan2015年04月08日 10:49:25 +00:00Commented Apr 8, 2015 at 10:49
-
I've just executed it from my Mac on the same network and it's not shutting down?Connor– Connor2015年04月08日 10:58:34 +00:00Commented Apr 8, 2015 at 10:58
-
There I can't help. I don't have an environment set-up to issue web commands to my Pi. Apache/PHP should log errors on the Pi somewhere.joan– joan2015年04月08日 11:17:57 +00:00Commented Apr 8, 2015 at 11:17
1 Answer 1
You can't. Not without additional hardware.
There is no "off"-switch on the pi - when it's plugged in, it is powered.
You can put it in a runlevel that makes it disappear from the net, and you can reboot it.
The reason your php-script doesn't work, however, is probably that the user it is executing as does not have the rights to run the shutdown
-command. This should show up in the /var/log/syslog
-file.
-
I mean shutdown - and how would I give the user the correct permissions?Connor– Connor2015年04月08日 13:51:37 +00:00Commented Apr 8, 2015 at 13:51
-
That is why joan suggested
sudo shutdown...
. So make sure the respective user has the right tosudo
see en.wikipedia.org/wiki/Sudo There should be a special user that runs apache/php.2015年04月08日 14:49:09 +00:00Commented Apr 8, 2015 at 14:49