in reply to Re^3: perl script using sudo
in thread perl script using sudo

I solved this problem

this perl code does his job very well:
system `/usr/local/www/cgi-bin/ntop/ntop.sh stop` or die "cannot stop +ntop: $!"; sleep(8); $cc = `sudo /usr/local/www/cgi-bin/ntop/ntop.sh start` or die "cannot +start ntop: $!"; print "status:</font> ",$cc,"\n";


Now I can stop and start ntop via browser !

greetings
cc

Replies are listed 'Best First'.
Re^5: perl script using sudo
by halley (Prior) on Jul 24, 2005 at 16:48 UTC
    You're still using backticks. You know, the little ` ` marks? And now you're using backticks and then calling system() with the RESULTS of the backticks. Er, hello?!
    my $val = system("/usr/local/www/cgi-bin/ntop/ntop.sh stop"); die "command got results of $val" if $val != 0;
    Use regular strings to describe your command, and give that as an argument to the system() function. That runs a command. It returns a NUMBER result, such as 0 for success. As mentioned before, backticks returns a STRING of the program's output, which is a silly way to check for basic success in most cases.

    --
    [ e d @ h a l l e y . c c ]