Today, we are going to discuss about an interesting and useful utility called "shell2http" that can be used to execute shell commands via http server. You can run any commands on your Linux box, and send the output to your colleague or friend on the local network to review them. S/He can view the output on a web browser. This tool might be useful if you don't want to give the SSH access to your friend. Just ask him what command's output he would like to see, and run that command in your local system and allow him to view it on his web browser from anywhere on the local network. Your friend doesn't need an SSH access to view the results of any output.
shell2http - Execute Shell Commands Via HTTP Server
shell2http can be downloaded from the following link depending upon the distribution you use. It will support GNU/Linux, Windows, and Mac OS X.
Or, run the following commands to download it from the Terminal:
Make sure you have installed the command line downloader wget and compression tool unzip.
On RPM based systems, run the following command as root user to install them.
$ yum install wget unzip
On DEB based systems, run:
$ sudo apt-get install wget unzip
To download 64 bit shell2http:
$ wget https://github.com/msoap/shell2http/releases/download/1.7/shell2http-1.7.linux.amd64.zip
To download 32-bit shellhttp:
$ wget https://github.com/msoap/shell2http/releases/download/1.7/shell2http-1.7.linux.386.zip
Extract the compressed file in any location of your choice.
$ unzip shell2http-1.7.linux.xxx.zip
Go to the extracted folder, and start using shell2http.
Let us say your friend wants to view the installed Linux Kernel version of your system.
To do so, run:
$ shell2http -host 192.168.1.150 -port 8080 /kernel "uname -r"
Here, 192.168.1.150 is your local system's IP address. 8080 is the port number. /kernel - is the path to view the command's output. And "uname -r" is the command to display your system's Kernel version.
2017/02/03 14:57:21 register: /kernel (uname -r) 2017/02/03 14:57:21 listen http://192.168.1.150:8080/
You probably need to open the port "8080" in your firewall or router. On systems that use firewalld (E.g RHEL, CentOS), run the following command as root user to open port 8080:
# firewall-cmd --add-port=8080/tcp --permanent
Restart firewalld service using command:
# firewall-cmd --reload
On Debian and Ubuntu systems, run:
$ sudo ufw allow 8080
Just make sure the port 8080 hasn't been used by any other applications. If it is, mention different port in the command and allow that port via firewall too.
Now, tell your friend to open his web browser and point it to "http://IP-address:8080/kernel" or "http://hostname:8080/kernel". It's simple as that.
If your friend wants to analyze the disk usage, just run the following command on your local system.
$ shell2http -host 192.168.1.150 -port 8080 /diskusage "du -h"
And, ask him to open the path - http://IP-address:8080/diskusage in his web browser.
To exit the command, press CTRL+C.
Quite handy, isn't? Of course, it is!
You can also combine two commands and send the outputs to your friend like below.
In the below example, I am going to run du and ps commands and send the output to http server.
$ shell2http /diskspace "df -h" /ps "ps aux"2017/02/03 15:09:34 register: /diskspace (df -h)
2017/02/03 15:09:34 register: /ps (ps aux) 2017/02/03 15:09:34 listen http://:8080/
Did you notice the above command? I didn't mention the IP address of my system. shell2http will work without mentioning the IP address or hostname too.
Now, your friend can view the output of diskspace from the URL - http://IP-address:8080/diskspace, and view the output of "ps" command using URL - http://IP-address:8080/ps.
PS command output:
Disclaimer: Use shell2http tool with caution inside your trusted network only. Your server can easily be compromised if you didn't take the necessary precautions.