[Ssh-sftp-perl-users] Everything works except the password... Hm-mm
Brought to you by:
dbrobins
From: Ron S. <gee...@ya...> - 2009-04-05 18:35:44
|
Hi all, Everything works except the password. What am I missing/doing wrong? #!/usr/bin/perl use warnings; use strict; use Net::SSH::Perl; my ($host, $user, $pass) = qw(someHost someUser somePassword); my $ps_cmd = 'ps -ef | grep someProcess.sh | grep -v grep'; my $start_cmd = 'sudo -S /usr/local/bin/someProcess.sh'; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my ($stdout, $stderr, $exit) = $ssh->cmd($ps_cmd); if (!defined $stdout) { my $stdin = "password_passed_to_Sudo"; print "\n'someProcess.sh' is not running. An attempt will be made to restart it.\n\n"; ($stdout, $stderr, $exit) = $ssh->cmd($start_cmd, $stdin); } else { print "\n'someProcess.sh' is running. No action is necessary.\n\n"; } $ssh->cmd("exit"); It looks like I get connected OK. The grep for the running process is OK. The if statement works fine. I'm running into trouble getting Sudo to accept the password in order to restart the process. Following is the output from the debugger: 25==> $ssh->cmd("exit"); DB<8> x $stdout, $stderr, $exit, $stdin 0 ' ### Sun Apr 5 17:49:30 GMT 2009 - Establishing SSH port forwarding session ### ### Sun Apr 5 17:49:30 GMT 2009 - SSH port forwarding session ended ### ' 1 "OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003\cJdebug1: Reading configuration data /etc/ssh/ssh_config\cM\cJdebug1: Applying options for *\cM\cJdebug1: Connecting to 172.25.101.154 [172.25.101.154] port 22.\cM\cJdebug1: Connection established.\cM\cJdebug1: permanently_set_uid: 0/0\cM\cJdebug1: identity file /root/.ssh/identity type -1\cM\cJdebug1: Remote protocol version 1.99, remote software version OpenSSH_3.1p1\cM\cJdebug1: match: OpenSSH_3.1p1 pat OpenSSH_2.*,OpenSSH_3.0*,OpenSSH_3.1*\cM\cJdebug1: Local version string SSH-1.5-OpenSSH_3.9p1\cM\cJdebug1: Waiting for server public key.\cM\cJdebug1: Received server public key (768 bits) and host key (1024 bits).\cM\cJdebug1: Host '172.25.101.154' is known and matches the RSA1 host key.\cM\cJdebug1: Found key in /root/.ssh/known_hosts:11\cM\cJdebug1: Encryption type: 3des\cM\cJdebug1: Sent encrypted session key.\cM\cJdebug1: Installing crc compensation attack detector.\cM\cJdebug1: Received encrypted confirmation.\cM\cJdebug1: Doing challenge response authentication.\cM\cJdebug1: No challenge.\cM\cJdebug1: Doing password authentication.\cM\cJPermission denied, please try again.\cM\cJPermission denied, please try again.\cM\cJPermission denied.\cM\cJ" 2 0 3 undef DB<9> q At zero, $stdout says a session was established for a time. At 1, $stderr gives me the story of what happened. It looks like $exit gives the 0; I think this is correct. But, I'm unsure as to if $stdin should be undef at 3. Any help would be greatly appreciated. Ron Smith gee...@ya... |