in reply to Re^5: Shell to Perl conversion
in thread Shell to Perl conversion

I am trying hard to run the below line with sudo, I am not able to handle the password prompt in my script. You are perfectly correct about your observation about permission problem. I have two option for that, either to use ssh command in a shell file and then call it like below:
`/bin/sh /tmp/rockpingping.sh $nodeName > /tmp/result.txt`;
The above solution is working, but it is not a good way of doing things. And the second option is using sudo. I am not succeeding sudo option where it password prompt is popping up.
cheers Rock
$flag = system("sudo /bin/sh /tmp/sshping.sh > /tmp/result.txt" ); + ## '>' is the redirect operator and test.sh is the shell script If ($flag == 0 ) { // The success result will be stored at result.txt // need to open this file and then use it } else { // failure case }

Replies are listed 'Best First'.
Re^7: Shell to Perl conversion
by Corion (Patriarch) on Aug 31, 2008 at 08:50 UTC

    You won't be able to handle any password prompt by ssh in your script. This is why I mentioned passwordless keys. Also, there is little difference between `/bin/sh ...` (and throwing the result away) and system(). If the backticks work for you, you can now move the contents of the shell script into that command line and use that.

    You might want to read up about backticks in perlop - you don't need redirection with backticks because they return the script output:

    my @output = `/bin/sh ...`; print "I got: @output";

    Let me repeat: You won't be able to supply a password to sudo or ssh.

      I found out that In my CGI script, the Form data is not being transffered from webpage to underlying script. What could be the workaround for ward of the permission problem between, Operating system user and Webinterface user.
      cheers Rock

        I don't see how this question relates to your original question. Maybe you can post the script together with a description of the problem. Or maybe you can debug it yourself. For example, usually the web server error log has a detailed description of the problems Perl or the webserver encounter.

        I cannot suggest a workaround because you describe the problem quite poorly.