I am trying to execute a shell script to shutdown a FreeNAS serve from my web server. I want to be able to click a button or just type in a url to execute the script from my raspberry pi that will shutdown a different computer (freenas).
Currently, I have setup ssh keys and I can connect from my raspberry pi to freenas fine through ssh.
This is my command that successfully turns off my freenas when executing it from terminal/putty whilst already sshed into my raspberry pi:
^^^^ this works.
pi@raspberrypi ~ $ sudo ssh email@example.com -i /etc/ssh/freenas-root_rsa 'shutdown -p now'
shutdown: [pid 16089]
Now onto the next step which I am having trouble with.
I created a .sh script e.g. shutdown.sh and put this into /usr/lib/cgi-bin directory. Script is as below. Permissions set to 755 so it's executable.
Now when I try to execute it by url:
sudo ssh firstname.lastname@example.org -i /etc/ssh/freenas-root_rsa 'shutdown -p now'
nothing happens to my frenas server.
I do get a server 500 error but i assume this is because there is no html for the page to load.
How can I get this script to work when executing it from a html <a>, or <button> button or just from entering a URL as above.