in reply to Perl CGI ability to start linux services

I tried running with sudo but without success.

What was the error?

Have you configured sudo appropriately, granting the apache user the respective permissions?

Replies are listed 'Best First'.
Re^2: Perl CGI ability to start linux services
by iphony (Acolyte) on Nov 29, 2008 at 01:50 UTC
    It returns me code 256. for example: my $val = `/etc/init.d/ntpd start`; The value of $val is 256.

      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.
      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.