Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was wondering what is needed to trigger a shell script with a HTTP post request. Being in my home wifi I want to call http://ip.of.host/req?run and have a script triggered on my host. I guess I have to run a webserver on the host. But what else is needed in addition? Is this the right place to ask that kind of question? Thanks!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

This is a very broad question. I would install Apache and PHP on the server and then you can use a very simple PHP script to run the script. Nothing else should be required.

In your web root directory, place a script and a php file:

script.sh:

#!/bin/bash

echo "Hello World"

run_script.php:

<?php
    $output = shell_exec('./script.sh');
    echo $output;
?>

Run this using localhost/run_script.php.

You can then run any script you want (you should not place it in your web root!)

If you only want to run this on an HTTP Post request, then wrap the script in

if ($_SERVER['REQUEST_METHOD'] === 'POST') { ... }

And you can check for Post parameters with

if ($_POST['parameter']) { ... }

Note: There are many caveats with this, but they are better addressed as separate questions. This should get you going, anyway.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.