in reply to Re: Perl CGI ability to start linux services
in thread Perl CGI ability to start linux services

It returns me code 256. for example: my $val = `/etc/init.d/ntpd start`; The value of $val is 256.
  • Comment on Re^2: Perl CGI ability to start linux services

Replies are listed 'Best First'.
Re^3: Perl CGI ability to start linux services
by almut (Canon) on Nov 29, 2008 at 02:14 UTC

    I don't see you using sudo anywhere... (that would be sudo /etc/init.d/ntpd start).

    To avoid having to mess with entering passwords, it's probably best to make use of the NOPASSWD: option, e.g. something like (in /etc/sudoers):

    apache localhost = NOPASSWD: /etc/init.d/ntpd

    (see man sudoers for the details)

      Thanks! This works when password is disabled.
Re^3: Perl CGI ability to start linux services
by eye (Chaplain) on Nov 29, 2008 at 06:22 UTC
    If an error occurred, its code will be found in $?, not $val. Moreover, the exit status will be found in the high byte:
    $? >> 8
    As an aside, if you are running this on a Red Hat derivative, this could be an selinux issue. See thread "Premature end of script headers more annoying than usual . . ." for suggestions on determining if selinux is the source of the problem.