Thread: [Ssh-sftp-perl-users] Net::SSH::Expect
Brought to you by:
dbrobins
From: David M. F. <mf...@tr...> - 2007-12-31 00:10:16
|
Folks, I want to ssh into my aix server and run the passwd interactive command to change password automatically. However, The waitfor never works correctly. It always dies with prompt 'Password:' not found after 1 seconds Actual ssh session: Server1[/home/user1]$ sudo passwd user2 Password: Changing password for "user2" user2's New password: Enter the new password again: Code snippet: use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => "$sship", port => 22, password=> "$pass", user => "$user", raw_pty => 1 ); # 2) logon to the SSH server using those credentials. # test the login output to make sure we had success my $login_output = $ssh->login(); print "Login Output->$login_output<-\n"; if ($login_output !~ /Wlecome/) { die "Login has failed. Login output was $login_output"; } else { print "Login Successful!!\n"; } # Now let's run an interactive command, like passwd. # This is done combining send() and waitfor() methods together: print "Sending Command->sudo passwd $userid<-\n"; $ssh->exec("sudo passwd $userid"); $ssh->waitfor('Password:', 1) or die "prompt 'Password:' not found after 1 seconds"; print "Sending Password->$pass<-\n"; $ssh->send("$pass"); $ssh->waitfor('New password:\s*\z', 1) or warn "prompt 'New password:' not found"; print "Sending Temporary Password->$temp_pass<-\n"; $ssh->exec("$temp_pass"); $ssh->waitfor('new password again:\s*\z', 1) or warn "prompt 'Confirm new password:' not found"; print "Sending Temporary Password again->$temp_pass<-\n"; $ssh->exec("$temp_pass"); # check that we have the system prompt again. $ssh->waitfor('$\s*\z', 1) or warn "No System Prompt\n"; $ssh->send("exit"); # closes the ssh connection $ssh->close(); } 1; TIA, Mark |
From: Mik J <mik...@ya...> - 2008-01-16 13:58:08
|
Hello, I have a Cisco router on which I'm able to scp the configuration file in command line but sftp doesn't work from the command line. I'd like to know if Net::SFTP is able to connect to the routeur in the scp mode only not using the sftp functionality. Does anyone tryed to do this or know how to retrive a file from a system that doesn't support sftp ? _____________________________________________________________________________ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail http://mail.yahoo.fr |
From: Heiko J. <ja...@hb...> - 2008-01-16 14:12:53
|
Am Mittwoch, den 16.01.2008, 14:57 +0100 schrieb Mik J: > I have a Cisco router on which I'm able to scp the > configuration file in command line but sftp doesn't > work from the command line. > I'd like to know if Net::SFTP is able to connect to > the routeur in the scp mode only not using the sftp > functionality. >From what I see in the docs, I'd say no. Besides, it is explicitly named Net::SFTP... > Does anyone tryed to do this or know how to retrive a > file from a system that doesn't support sftp ? I'd suggest using Net::SCP (which is only a wrapper around the command line scp) or - presumably even better - Net::SSH2 which has a built-in scp subcommand. heiko |
From: Mik J <mik...@ya...> - 2008-01-16 22:13:43
|
Thank you, --- Heiko Jansen <ja...@hb...> a écrit : > > I have a Cisco router on which I'm able to scp the > > configuration file in command line but sftp > > doesn't work from the command line. > > I'd like to know if Net::SFTP is able to connect > > to the routeur in the scp mode only not using the > > sftp functionality. > > From what I see in the docs, I'd say no. Besides, > it is explicitly named Net::SFTP... I read correctly the name of this module and I know it's SFTP. But it seemed strange to me that there was a SSH module, a SFTP module and no SCP. I thought the SCP functionality was included in the SFTP module. > I'd suggest using Net::SCP (which is only a wrapper > around the command line scp) I can't use the Net::SCP for the reason below "Q: How do you supply a password to connect with ssh within a perl script using the Net::SSH module? A: You don't (at least not with this module). Use RSA or DSA keys. See the quick help in the next section and the ssh-keygen(1) manpage. A #2: See Net::SCP::Expect instead. " My routers accept only password authentication. > or - presumably even > better - Net::SSH2 which has a built-in > scp subcommand. I did not manage to make Net::SSH2 with the scp option to work when trying to secure copy my router's configuration. #!/usr/bin/perl use Net::SSH2; $cisco = '10.1.1.1'; $user = 'miky'; $pass = 'mypass'; $cfg_run = 'RUNCFG'; $cisco_run = 'running-config'; my $ssh2 = Net::SSH2->new(); $ssh2->debug(1); $ssh2->connect($cisco) or warn "Can't open connection to $host\n"; $ssh2->auth_password($user, $pass); $ssh2->scp_get($cisco_run,$cfg_run); print "\n"; $ ./scpcisco.pl libssh2_scp_recv(ss->session, path, &st) -> 0x0 Net::SSH2::DESTROY object 0x80e0d40 and the file RUNCFG is not created _____________________________________________________________________________ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail http://mail.yahoo.fr |
From: Heiko J. <ja...@hb...> - 2008-01-17 08:20:46
|
Am Mittwoch, den 16.01.2008, 23:13 +0100 schrieb Mik J: > > > I'd suggest using Net::SCP (which is only a wrapper > > around the command line scp) > > I can't use the Net::SCP for the reason below > "Q: How do you supply a password to connect with ssh > within a perl script using the Net::SSH module? > A: You don't (at least not with this module). Use RSA > or DSA keys. See the quick help in the next section > and the ssh-keygen(1) manpage. > A #2: See Net::SCP::Expect instead. > " > My routers accept only password authentication. So you try Net::SCP::Expect instead, as proposed. > I did not manage to make Net::SSH2 with the scp option > to work when trying to secure copy my router's > configuration. > > #!/usr/bin/perl > use Net::SSH2; > $cisco = '10.1.1.1'; > $user = 'miky'; > $pass = 'mypass'; > $cfg_run = 'RUNCFG'; > $cisco_run = 'running-config'; > my $ssh2 = Net::SSH2->new(); > $ssh2->debug(1); > $ssh2->connect($cisco) or warn "Can't open connection > to $host\n"; > $ssh2->auth_password($user, $pass); > $ssh2->scp_get($cisco_run,$cfg_run); > print "\n"; > > > $ ./scpcisco.pl > libssh2_scp_recv(ss->session, path, &st) -> 0x0 > Net::SSH2::DESTROY object 0x80e0d40 > and the file RUNCFG is not created First, make sure you have libssh2 0.18 and Net::SSH2 0.18. Previous versions had problems. Even though I have these versions your script did not work for me at first either: when I started it, it simply hang without printing any debug messages... I had to replace "auth_password" with "auth_keyboard" to get it to work. However, I could test that only with a linux server running OpenSSH - I do not have a cisco router here for testing so my solution might no be applicable to your environment. Heiko |
From: Heiko J. <ja...@hb...> - 2008-01-17 08:24:31
|
Am Donnerstag, den 17.01.2008, 09:20 +0100 schrieb Heiko Jansen: > So you try Net::SCP::Expect instead, as proposed. Should have been "So you _could_ try..." By the way: If "auth_keyboard" does not work, I don't have any other ideas about what might help. Maybe the router has a log where one could find hints on what's going wrong. Otherwise: Real experts to the rescue ;-) heiko |
From: Mik J <mik...@ya...> - 2008-01-18 16:23:22
|
--- Heiko Jansen <ja...@hb...> a écrit : > Am Mittwoch, den 16.01.2008, 23:13 +0100 schrieb Mik > J: > > > > > I'd suggest using Net::SCP (which is only a > wrapper > > > around the command line scp) > > > > I can't use the Net::SCP for the reason below > > "Q: How do you supply a password to connect with > ssh > > within a perl script using the Net::SSH module? > > A: You don't (at least not with this module). Use > RSA > > or DSA keys. See the quick help in the next > section > > and the ssh-keygen(1) manpage. > > A #2: See Net::SCP::Expect instead. > > " > > My routers accept only password authentication. > > So you try Net::SCP::Expect instead, as proposed. > > > I did not manage to make Net::SSH2 with the scp > option > > to work when trying to secure copy my router's > > configuration. > > > > #!/usr/bin/perl > > use Net::SSH2; > > $cisco = '10.1.1.1'; > > $user = 'miky'; > > $pass = 'mypass'; > > $cfg_run = 'RUNCFG'; > > $cisco_run = 'running-config'; > > my $ssh2 = Net::SSH2->new(); > > $ssh2->debug(1); > > $ssh2->connect($cisco) or warn "Can't open > connection > > to $host\n"; > > $ssh2->auth_password($user, $pass); > > $ssh2->scp_get($cisco_run,$cfg_run); > > print "\n"; > > > > > > $ ./scpcisco.pl > > libssh2_scp_recv(ss->session, path, &st) -> 0x0 > > Net::SSH2::DESTROY object 0x80e0d40 > > and the file RUNCFG is not created > > First, make sure you have libssh2 0.18 and Net::SSH2 > 0.18. Previous > versions had problems. I was using the 0.17 version > Even though I have these versions your script did > not work for me at > first either: when I started it, it simply hang > without printing any > debug messages... > I had to replace "auth_password" with > "auth_keyboard" to get it to work. I made this replacement but it did not work My script already works with Net::Telnet::Cisco or Net::Telnet but I wanted it to work with a secure protocol such as ssh. I didn't try to make it work with snmp because I dont know much about this protocol except that it's quite difficult to make things due to different OID on different IOS Thanx for you two, I guess that it won't work this way. I'm working on the other side with Net::Appliance::Session through ssh (not scp) _____________________________________________________________________________ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail http://mail.yahoo.fr |
From: Torben P. E. <TP...@da...> - 2008-01-17 22:01:30
|
Cisco routers have build in backup capabilities. You could use SNMP to make the router push it's configuration with TFTP, = FTP or SCP. http://www.cisco.com/en/US/products/sw/iosswrel/ps5207/products_feature_g= uide09186a00801a75a3.html By the way. Cisco recommends using a separate VLAN for management and = backup. So telnet would be a option with that solution.=20 -----Oprindelig meddelelse----- Fra: ssh...@li... = [mailto:ssh...@li...] P=E5 vegne af = Mik J Sendt: 16. januar 2008 23:13 Til: ssh...@li... Emne: [Ssh-sftp-perl-users] RE : Re: Scp capability but no sftp = capability |