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:

$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 Apr 8 '15 at 10:43
  • I'm not exactly a Linux genius :P , you might have to explain how I would go about doing such a thing – Connor Apr 8 '15 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 Apr 8 '15 at 10:49
  • I've just executed it from my Mac on the same network and it's not shutting down? – Connor Apr 8 '15 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 Apr 8 '15 at 11:17

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 Apr 8 '15 at 13:51
  • That is why joan suggested sudo shutdown.... So make sure the respective user has the right to sudo see en.wikipedia.org/wiki/Sudo There should be a special user that runs apache/php. – Ghanima Apr 8 '15 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.