0

I'm able to pass a variable from HTML form to a simple perl script. This is the main line from perl script.

 system("/var/www/cgi-bin/aaa $name")

The perl script calls a bash script called aaa. As you see I pass the $name which is the entry from my html form to aaa bash script. In my bash script I can echo the $name as $1 or assign $1 to $name. So so far so good. That's the way I want it. However in my aaa bash script I have a ssh command in aaa script that is not working. No matter how many different way I tried it it just not working. If I run the aaa script command from command line and pass a parameter , the script works fine, but when I try it via the perl it fails.

my ssh command right now is very simple. So my aaa bash file contains a simple line

 echo $1      
 ssh $1 "ls -altr" > /var/www/cgi-bin/output

If I call this script from command line ( aaa serverx ) It works fine. Now I do it through the html form and the only thing that works is the echo $1 command. Another word I can see that I'm passing the right servername ( example serverx) and when I do echo $1 I can see the serverx. However, the ssh line fails. Noyt sure what to do ? Can anyone help ?

Regards

5
  • Did you just stutter online? Commented Jan 10, 2015 at 21:58
  • 1
    Are you running the PHP script from the webserver? It won't use your SSH username or private key. Commented Jan 10, 2015 at 22:01
  • @matthewthegreat You might want to quote your variables (although it probably won't solve the problem it should add some protection). Commented Jan 10, 2015 at 22:02
  • Barmer - I'm running the bash script from the webserver. The bash as I mentioned works fine from command line. Biffen, I tried the quote. I tried various options. Just not sure why ssh is failing withing the script. Commented Jan 10, 2015 at 22:05
  • thank you all appreciated. I'm trying to find how I can do the ssh directly from perl without passing the param to another bash file. stackoverflow.com/questions/27890239/… Commented Jan 11, 2015 at 17:59

1 Answer 1

0

Ideally you should do things within Perl script there should be no need for aaa script, There might be many reasons why ssh is not working, it could be simply because you closed STDIN , STDOUT at the higher level or have redirection enabled ? That might simply explain why it works from command line but not from another wrapper.. Have you tried to run ssh inside the perl script and see if that works? Is it possible to share some parts of code snippet?

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

1 Comment

Hi Thanks. I re-stated my question following yoru advice. Hopefully someone will reply stackoverflow.com/questions/27890239/…

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.