0

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.

asked Apr 8, 2015 at 10:38
10
  • 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? Commented 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 thing Commented 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"); Commented Apr 8, 2015 at 10:49
  • I've just executed it from my Mac on the same network and it's not shutting down? Commented 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. Commented Apr 8, 2015 at 11:17

1 Answer 1

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.

answered Apr 8, 2015 at 13:45
2
  • I mean shutdown - and how would I give the user the correct permissions? Commented Apr 8, 2015 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. Commented Apr 8, 2015 at 14:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.