Search code examples
bashexecution

Execute a bash script in remote server through URL


I have a bash script "Hello.sh" below in my remote server "A" which is running Apache.

#! /bin/bash
echo "Hello World" > Hello.txt

I want to execute this script in remote server "A" itself by calling it's Apache URL from server "B" like below.

Please note I have made the script available through URL by keeping it in Document root of Apache.

http://Server_A:PORT/Hello.sh

How can this be accomplished. Thanks.


Solution

  • To be able to run shell scripts directly from the browser, you should add this rule to your .htaccess file.

    Options ExecCGI AddHandler cgi-script .sh

    This tells the webserver to treat .sh files as CGI scripts.