maguilu has asked for the wisdom of the Perl Monks concerning the following question:

Need some help, Have been looking for any solutions and more than likely is something simple but i am too new to this stuff. Here is my problem I need to execute a series of commands and display the output on a page. Some limitations, - the user i using is able to ssh to servers without password. (user1) - the web server executing the script runs under root So i need to sudo the ssh user1@server echo "someotherserver" I believe my problem is with the syntax from the many concatenated commands Here is the section that is killing. (did i mention i am way new to this, On 2 days as of 12/22/14) Tried with No luck

my $dwfssh = "/usr/bin/sudo -u netcool /usr/bin/ssh -t user1\@serverna +me"; #Ping Route Section print "<p class=\"systemMsg\">Pinging $msg1 from Orlando </p>"; #open(PINGORF,"$dfwssh '/bin/ping -c 5 -q ".$test1."'|"); open(PINGORF,"/bin/ping -c 3 ".$test1."|"); $old_fh = select(STDOUT); $| = 1; select($old_fh); print "<PRE><p class=\"results\">"; while(<PINGORF>) { print; } print "</p></PRE>"; print "<p class=\"systemMsg\">Pinging $msg1 from Dallas </p>"; #open(PINGDWF,"$dfwssh '/bin/ping -c 5 -q ".$test1."'|"); $cmd1 = "/usr/bin/sudo -u 'user1 echo "Darn thing wont workr"'"; open(PINGDWF,"$cmd1"); #open(PING,"/bin/ping -c 10 ".$test1."|"); $old_fh = select(STDOUT); $| = 1; select($old_fh); print "<PRE><p class=\"results\">"; while(<PINGDWF>) { print; } print "</PRE></p>";

btw: i also tried the full command instead the variables in the Open thing I am able to run the echo and other commands in the script from the command line without problems but i place them back here i get No output..

Replies are listed 'Best First'.
Re: Perl CGI SUDO -> SSH -> Command
by Corion (Patriarch) on Dec 23, 2014 at 07:41 UTC

    Most likely, your CGI is not run as root, or sudo does not want to execute from the webserver. Maybe you can find more information in the web server error log or in the sudo log.

    Personally, I would look at Net::Ping to construct and send the ping packets.

Re: Perl CGI SUDO -> SSH -> Command
by salva (Canon) on Dec 23, 2014 at 11:21 UTC
    If you are really root, you probably don't need sudo at all. Just tell ssh to authenticate using the user's private key. For instance:
    ssh -i /home/user/.ssh/id_dsa host
Re: Perl CGI SUDO -> SSH -> Command
by Anonymous Monk on Dec 23, 2014 at 11:27 UTC
    $cmd1 = "/usr/bin/sudo -u 'user1 echo "Darn thing wont workr"'";
    Yes that's a syntax error. Why didn't you tell exactly what error you got? You should always do that.

    Now people think you have some problems with ssh, sudo or some such instead of you being unable to compile your script