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

When you run the script from a normal prompt, you're running it as your normal user account, not www. So I would think that it's still the sudo requiring password issue. Either run the script from the command line using sudo -u www (something like: sudo -u www perl /path/to/perl/script.cgi) or add your normal account to the sudoers file.

Replies are listed 'Best First'.
Re^4: perl script using sudo
by cc (Beadle) on Jul 24, 2005 at 01:01 UTC
    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
      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 ]