
If I like to run a terminal command from my webpage, what is the best way then?
I like to have button to push if for example I wan't to restart my raspberry pi or if I like to run "wakeonlan 00:00:00:00:00:00"
Code: Select all
#!/bin/bash
echo "Ping" >> /tmp/cgi-called.log
cat << EOF
Content-type: text/html
<html>
<head>
<title>Cgi Script</title>
</head>
<body>
CGI Script ran, check out /tmp/cgi-called.log to see how many times
</body>
</html>
EOF
That was all I needed to do to get cgi working for me.CGI scripts are looked for in /usr/lib/cgi-bin, which is where Debian packages will place their scripts. You can enable cgi module by using command "lighty-enable-mod cgi".
Code: Select all
<html>
<head>
<title>Output of my bash script</title>
</head>
<body>
<h1>Output of my bash script</h1>
<pre>
<?php system("gphoto2 --capture-image", $rc); ?>
</pre>
<br>
<?php echo "Return Code: {$rc}\n"; ?>
</body>
</html>
Code: Select all
pi@raspberrypi ~ $ sudo su - www-data
$ /opt/vc/bin/vcgencmd measure_temp
VCHI initialization failed
Code: Select all
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_fastcgi",
"mod_redirect",
# "mod_rewrite",
)
server.document-root = "/var/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80
index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".cgi" )
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )
# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket"
)))
Code: Select all
sudo /home/pi/sources/Adafruit_Python_DHT/examples/AdafruitDHT.py 2302 4