Riley Willow
Riley Willow

Reputation: 594

Sending argument from CGI script as bash script argument

I am trying to pass the argument to my bash script through my cgi script. This may sound a little bit confusing, so here is the explanation,

I have bash script called script.sh which accept one argument lets say name so I execute this script like this,

bash script.sh myName

The name is then written in a text file, and then i can read it from that text file.

Which works just fine, but I want to be able to execute this same command through cgi, so I did this inside my cgi file,

`/bin/echo "bash script.sh myName"`;

Now I execute this cgi script through my webserver like this,

http://localhost/index.cgi

but myName is not passing as an argument to my bash script and hence nothing is written on the text file.

Can anyone please tell me why its not working when I am running through cgi script but working fine when run without a cgi script ?

EDIT: I have also tried using exec() but the argument still wouldn't pass.

Upvotes: 0

Views: 581

Answers (1)

Ruslan Osmanov
Ruslan Osmanov

Reputation: 21492

In the comments to the question you wrote that the CGI script was written in CSH.

Then it's as simple as the following.

script.csh

#!/bin/csh
./script.sh argX

script.sh

#!/bin/bash
echo 'hello,' $1

Testing script.csh

./script.csh 
hello, argX

It it isn't what you are looking for, please clarify.

Upvotes: 2

Related Questions