Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 92406

Executing shell script from web sever via URL/button?

$
0
0

Hey guys,

 

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:

 

pi@raspberrypi ~ $ sudo ssh root@192.168.2.141 -i /etc/ssh/freenas-root_rsa 'shutdown -p now'

Shutdown NOW!

shutdown: [pid 16089]

Shutdown NOW![/CODE]

          ^^^^ this works.

 

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.

 

#!/bin/bash

 

sudo ssh root@192.168.2.141 -i /etc/ssh/freenas-root_rsa 'shutdown -p now'

 

 

Now when I try to execute it by url:

http://192.168.2.11/cgi-bin/shutdown.sh

nothing happens to my freenas 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.

 

Thanks


Viewing all articles
Browse latest Browse all 92406

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>