0

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.

2
  • In what programming language the CGI script is written? Commented May 1, 2016 at 8:57
  • #!/bin/csh so its C-shell Commented May 1, 2016 at 9:03

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

suppose abcd is written in a text file, my bash script accept an argument and modify the value of abcd with that argument. when i run ./index.cgi it does it perfectly. but when i run it through webserver i.e http://localhost/index.cgi that doesn't happen, i.e. text file still says abcd.
do you have write permission to that directory ?
@RileyWillow, which server software are you running(Nginx, Apache, etc)? Is there something in the logs?
writing to /tmp/ directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.