I have a perl script that uses Net::OpenSSH and Net::Telnet. I am able to run the script from the command line of my server (solaris) and it seems to run correctly, including the ssh and telnet parts.

However, if I try to exec that script from php it doesnt work. The files the script is supposed to create do not get created, and in the error_log I see some errors related to libssh2.so and ssh2.so. However, my PHP code has no SSH related lines. Only the Perl does.

I see this line in the log quite a few times:

[Fri Apr 01 15:11:57 2016] [warn] (128)Network is unreachable: connect + to listener on [::]:443
I also see this:
ssh: illegal option -- M Usage: ssh [options] host [command] Options: -l user Log in using this user name. -n Redirect input from /dev/null. -F config Config file (default: ~/.ssh/config). -A Enable authentication agent forwarding. -a Disable authentication agent forwarding (default). -X Enable X11 connection forwarding. -x Disable X11 connection forwarding (default). -i file Identity for public key authentication (default: ~/.ssh/ +identity) -t Tty; allocate a tty even if command is given. -T Do not allocate a tty. -v Verbose; display verbose debugging messages. Multiple -v increases verbosity. -V Display version number only. -q Quiet; don't display any warning messages. -f Fork into background after authentication. -e char Set escape character; ``none'' = disable (default: ~). -c cipher Select encryption algorithm -m macs Specify MAC algorithms for protocol version 2. -p port Connect to this port. Server must be on the same port. -L listen-port:host:port Forward local port to remote address -R listen-port:host:port Forward remote port to local address These cause ssh to listen for connections on a port, and forward them to the other side by connecting to host:por +t. -D port Enable dynamic application-level port forwarding. -C Enable compression. -N Do not execute a shell or command. -g Allow remote hosts to connect to forwarded ports. -1 Force protocol version 1. -2 Force protocol version 2. -4 Use IPv4 only. -6 Use IPv6 only. -o 'option' Process the option as if it was read from a configuratio +n file. -s Invoke command (mandatory) as SSH2 subsystem. -b addr Local IP address. login failed: filehandle isn't open at /opt/apache/htdocs/enrc/cgi-bin +/metro_cm_tool.pl line 130

The PHP code:

<?php exec("/usr/bin/perl522/bin/perl /opt/apache/htdocs/enrc/cgi-bin/metro_ +cm_tool.pl"); ?>

I cant figure out what PHP is doing differently than when I run the script from the command line directly.


In reply to Execute a perl script from PHP? by jtzako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.