On 11/09/2011 04:57 AM, Agnello George wrote:
I am trying to run a shell script within a perl cgi script , however it is
not getting executed .

cat /vae/www/cg-bin/syscscript.pl
my $openvpn = `ps aux |grep openvpn |grep -v grep`;
unless ( $openvpn) {
system(" /usr/sbin/openvpn /etc/openvpn/DC.ovpn ");
}

When i run this file on command line ( perl /vae/www/cg-bin/syscscript.pl )
it works fine , but when i run it in the browser it does not execute  i
have even given root execution permission and apache ownership  ( chmod
4755 /usr/sbin/openvpn  ; chown  -R apache:apache  /usr/sbin/openvpn
/etc/openvpn   ) but still .... it gives me the following error

Nov  9 16:47:30 linux-qa openvpn[22812]: OpenVPN 2.1_rc4
x86_64-redhat-linux-gnu [SSL] [LZO2] [EPOLL] built on Feb 13 2011
Nov  9 16:47:30 linux-qa openvpn[22812]: WARNING: file
'/etc/openvpn/passwdfile' is group or others accessible
Nov  9 16:47:30 linux-qa openvpn[22812]: WARNING: No server certificate
verification method has been enabled.  See http://openvpn.net/
howto.html#mitm for more info.
Nov  9 16:47:30 linux-qa openvpn[22812]: Cannot load certificate file
agnello.crt: error:02001002:system library:fopen:No such file or
  directory: error:20074002:BIO routines:FILE_CTRL:system lib:
error:140AD002:SSL routines:SSL_CTX_use_certificate_file:system lib
Nov  9 16:47:30 linux-qa openvpn[22812]: Exiting

if any one has any idea it would be of great use , i have heard that people
generally create wrapper to work around this , but i dont know C  .


If you don't already have "CGI Programming with Perl", 2 e., you should get it:

    http://shop.oreilly.com/product/9781565924192.do


My guess is that your script depends upon your login shell environment (e.g. environment variables) and Apache is running as a different user with a different environment.


Can you:

        $ su -

and then:

        $ su -l apache

or whatever account Apache runs as, and then do some debugging?


In syscscript.pl, you should do error checking for the "ps aux" and "/usr/sbin/openvpn" steps. Backticks and system() both set the $? (child error) predefined special variable:

    $ perldoc perlvar


Chapter 16 of the Perl cookbook:

    http://shop.oreilly.com/product/9780596003135.do

has some advice for running other programs, capturing STDOUT, and/or capturing STDERR.


Another option is Capture::Tiny:

    http://search.cpan.org/~dagolden/Capture-Tiny-0.11/lib/Capture/Tiny.pm


I'm on Debian.  "man ps" cautions about "ps aux":

    Note that "ps -aux" is distinct from "ps aux". The POSIX and UNIX
    standards require that "ps -aux" print all processes owned by a
    user named "x", as well as printing all processes that would be
    selected by the -a option. If the user named "x" does not exist,
    this ps may interpret the command as "ps aux" instead and print a
    warning. This behavior is intended to aid in transitioning old
    scripts and habits. It is fragile, subject to change, and thus
    should not be relied upon.


Rather than invoking "ps aux" and shell piping/ grep'ing (or Perl scraping/ munging) the output, perhaps there is a CPAN module that accomplishes what you need (looking to see if "openvpn" is already running?). How about Proc::ProcessTable?

    http://search.cpan.org/~durist/Proc-ProcessTable-0.45/ProcessTable.pm


HTH,

David

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to