CPAN::Forum
Net-SSH-Perl - net-ssh-perl timeout
| Posted on Tue Jun 12 00:38:31 2007 by aels |
| net-ssh-perl timeout |
|
Hi, I would like to see if a process is running on a remote unix box (Solaris/Linux/HPUX etc), from a linux server. I am using the basic 'ps -ef | grep -v grep | grep -i "$process" ' to get the result back. I have two scenario's. 1. A stand-alone script using net-ssh-perl to execute the above. example: ====================== #!/usr/bin/perl use strict; use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new('10.2.2.10',debug => 1, protocol => '2,1'); $ssh->login('uername','password'); my ($stdout, $stderr, $exit) = $ssh->cmd('ps -ef | grep -v grep | grep pmon'); print $stdout . "\n"; print $stderr . "\n"; print $exit . "\n"; ====================== If I execute this it works fine on both Linux and Solaris. I get the following output (Solaris) with the ps command output at the end: ====================== thetamon: Reading configuration data /home/dbahist/.ssh/config thetamon: Reading configuration data /etc/ssh_config thetamon: Connecting to 150.50.0.165, port 22. thetamon: Remote version string: SSH-2.0-Sun_SSH_1.1 thetamon: Remote protocol version 2.0, remote software version Sun_SSH_1.1 thetamon: Net::SSH::Perl Version 1.30, protocol version 2.0. thetamon: No compat match: Sun_SSH_1.1. thetamon: Connection established. thetamon: Sent key-exchange init (KEXINIT), wait response. thetamon: Algorithms, c->s: 3des-cbc hmac-sha1 none thetamon: Algorithms, s->c: 3des-cbc hmac-sha1 none thetamon: Entering Diffie-Hellman Group 1 key exchange. thetamon: Sent DH public key, waiting for reply. thetamon: Received host key, type 'ssh-dss'. thetamon: Host '150.50.0.165' is known and matches the host key. thetamon: Computing shared secret key. thetamon: Verifying server signature. thetamon: Waiting for NEWKEYS message. thetamon: Enabling incoming encryption/MAC/compression. thetamon: Send NEWKEYS, enable outgoing encryption/MAC/compression. thetamon: Sending request for user-authentication service. thetamon: Service accepted: ssh-userauth. thetamon: Trying empty user-authentication request. thetamon: Authentication methods that can continue: publickey,password,keyboard-interactive. thetamon: Next method to try is publickey. thetamon: Next method to try is password. thetamon: Trying password authentication. thetamon: Login completed, opening dummy shell channel. thetamon: channel 0: new [client-session] thetamon: Requesting channel_open for channel 0. thetamon: channel 0: open confirm rwindow 0 rmax 32768 thetamon: Got channel open confirmation, requesting shell. thetamon: Requesting service shell on channel 0. thetamon: channel 1: new [client-session] thetamon: Requesting channel_open for channel 1. thetamon: Entering interactive session. thetamon: Sending command: ps -ef | grep -v grep | grep pmon thetamon: Requesting service exec on channel 1. thetamon: channel 1: open confirm rwindow 0 rmax 32768 thetamon: input_channel_request: rtype exit-status reply 0 thetamon: channel 1: rcvd eof thetamon: channel 1: output open -> drain thetamon: channel 1: rcvd close thetamon: channel 1: input open -> closed thetamon: channel 1: close_read thetamon: channel 1: obuf empty thetamon: channel 1: output drain -> closed thetamon: channel 1: close_write thetamon: channel 1: send close thetamon: channel 1: full closed oracle 29003 1 0 Jan 26 ? 0:02 ora_pmon_tcat oracle 731 1 0 Jan 25 ? 0:01 ora_pmon_genp ============================ But now I would like to move this script to run within Apache using the follwowing: "Apache/2.0.59 (Unix) mod_ssl/2.0.59 OpenSSL/0.9.7a mod_perl/2.0.3 Perl/v5.8.5" I created a basic form to select the server name, and then post it with a "process" to check. Example: ============================ #!/usr/bin/perl use CGI qw/:standard/; use Net::SSH::Perl; sub print_header() { print header(-expires=>'+1s'); print start_html(-title=>'Test'); } sub print_end() { print end_html; } my $cmd; &print_header; print start_form, 'Select Server '; print scrolling_list(-name=>'server', -size=>1, -default=>undef, -values=>['10.2.2.11','150.50.0.165']); print "<p>"; print "<em> What process are you looking for ? </em>"; print textfield('grepvalue'); print submit('Check'); print end_form; if (param('server')) { if (param('grepvalue')) { $cmd = 'ps -ef | grep -v grep | grep -i "' . param('grepvalue') . '"'; } else { $cmd = "ps -ef"; } $ip_address = param('server'); print "<p>"; my $ssh = Net::SSH::Perl->new($ip_address, debug => 1) ; $ssh->login('username','password'); my ($stdout, $stderr, $exit) = $ssh->cmd($cmd); $stdout =~ s/\n/\n<br>/g, $stdout; print "<font face=Courier>"; print "exit status " . $exit . " " . $stderr . "<br><br>"; print $stdout; print "<p>"; } &print_end; ================================= If I execute the above on the linux box. All works. If I do it connecting to Solaris, I get the output below. It seems as if it is waiting for the STDOUT to fill. Any Ideas? I have tried multiple options, but no luck. Initially the standalone script was really slow, but since I updated the Math-BigInt-GMP to the latest version it is now quit quick. But using the web site to check if the process is running it just hangs. ============================ thetamon: Reading configuration data /home/apache/.ssh/config thetamon: Reading configuration data /etc/ssh_config thetamon: Connecting to 150.50.0.165, port 22. thetamon: Remote version string: SSH-2.0-Sun_SSH_1.1 thetamon: Remote protocol version 2.0, remote software version Sun_SSH_1.1 thetamon: Net::SSH::Perl Version 1.30, protocol version 2.0. thetamon: No compat match: Sun_SSH_1.1. thetamon: Connection established. thetamon: Sent key-exchange init (KEXINIT), wait response. thetamon: Algorithms, c->s: 3des-cbc hmac-sha1 none thetamon: Algorithms, s->c: 3des-cbc hmac-sha1 none thetamon: Entering Diffie-Hellman Group 1 key exchange. thetamon: Sent DH public key, waiting for reply. thetamon: Received host key, type 'ssh-dss'. thetamon: Host '150.50.0.165' is known and matches the host key. thetamon: Computing shared secret key. thetamon: Verifying server signature. thetamon: Waiting for NEWKEYS message. thetamon: Enabling incoming encryption/MAC/compression. thetamon: Send NEWKEYS, enable outgoing encryption/MAC/compression. thetamon: Sending request for user-authentication service. thetamon: Service accepted: ssh-userauth. thetamon: Trying empty user-authentication request. thetamon: Authentication methods that can continue: publickey,password,keyboard-interactive. thetamon: Next method to try is publickey. thetamon: Next method to try is password. thetamon: Trying password authentication. thetamon: Login completed, opening dummy shell channel. thetamon: channel 0: new [client-session] thetamon: Requesting channel_open for channel 0. thetamon: channel 0: open confirm rwindow 0 rmax 32768 thetamon: Got channel open confirmation, requesting shell. thetamon: Requesting service shell on channel 0. thetamon: channel 1: new [client-session] thetamon: Requesting channel_open for channel 1. thetamon: Entering interactive session. thetamon: Sending command: ps -ef | grep -v grep | grep -i "pmon" thetamon: Requesting service exec on channel 1. thetamon: channel 1: open confirm rwindow 0 rmax 32768 thetamon: channel 1: rcvd eof thetamon: channel 1: output open -> drain thetamon: input_channel_request: rtype exit-status reply 0 thetamon: channel 1: rcvd close thetamon: channel 1: input open -> closed thetamon: channel 1: close_read ================================ |
| Direct Responses: 7829 | Write a response |
(9)
]