Re: [Ssh-sftp-perl-users] Everything works except the password... Hm-mm
Brought to you by:
dbrobins
From: Ron S. <gee...@ya...> - 2009-04-09 09:10:25
|
Hi Nigel, I finally got back into work to try your suggestion. I tried: echo "thePasswd"|sudo -S "whatever command" but that didn't work. I also tried the 'cat' version. But I don't know if I did that one correctly I tried: cat /path/to/somePasswdFile.txt | sudo -S /path/to/some/script.sh Wow! I've tried a number of things to no avail on this one. Maybe its a matter of entering the return character. All I know is when I manually execute the 'sudo' and type in the password from the command line, it always works. So, I'm figuring my troubles have something to with the process I'm trying to submit a password to, expecting input from a shell/command line or I'm missing the carriage return. I'm pretty sure this can be done using Perl, but I'm missing some key info. Hm-mm! ...any other thoughts? Ron Smith gee...@ya... --- On Sun, 4/5/09, Nigel Reed <ni...@sy...> wrote: > From: Nigel Reed <ni...@sy...> > Subject: Re: [Ssh-sftp-perl-users] Everything works except the password... Hm-mm > To: gee...@ya... > Date: Sunday, April 5, 2009, 1:41 PM > I believe to use -S you would need > > echo "mypass"|sudo -S "whatever > command" > > The problem is, a ps -ef will show the password. > > A couple of options is to use the NOPASSWD option for the > sudo command for > this user or store the password locally in a user only > readable file and > then cat the file to the sudo command. > > Ron Smith wrote: > > > > 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... > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > > Ssh-sftp-perl-users mailing list > > Ssh...@li... > > > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > > > > > -- > Nigel Reed > Candidate for Lieutenant Governor of Marketing 2009-2010 > > President & CEO Sysadmin, Inc > 972 673 4199 http://www.sysadmininc.com > Toastmasters District 50 Vista Division Governor 2008-2009 > Awareness, Attitude and Action bring Achievement! |