LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-23-2015, 09:34 AM   #1
rd700
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Rep: Reputation: Disabled
ssh to multiple host - expect script


hi guys, please help, i know my code below is very rudimentary,sorry.. as newbie as i am i still need to find a script that would enable me to do ssh to multiple cisco devices and do a backup config.. feel free to delete/change anything that is not pertinent to my goal..

---------------------
#!/usr/bin/expect -f

set timer 1
set password xxx
set ip x.x.x.x
set server x.x.x.x

spawn ssh rd700\@$ip


expect "*?assword:"
send -- "$password\r"
expect "*#>"
send "enable\r"l

expect "?assword:"
send -- "$password\r"

send -- "\r"

expect "*#"
send "copy running-config tftp:\r"
expect "Source filename:*"
send "\r"
expect "?host"
send "$server\r"

expect "?ilename*"
send "\r"

expect "?copied*"
send "exit\r
 
Old 11-23-2015, 10:56 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
You posted a script, but didn't say what it doesn't do that you do want, or what it does do that you don't want. What is it you're asking here?
 
Old 11-23-2015, 09:51 PM   #3
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Rep: Reputation: 72
Welcome to the forums!

Please take time to read this sticky.

For readability's sake, please wrap your commands in [ CODE ] tags. We don't want to drive people away just by irritating their eyes with unformatted commands.
 
Old 11-24-2015, 02:56 AM   #4
rd700
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
You posted a script, but didn't say what it doesn't do that you do want, or what it does do that you don't want. What is it you're asking here?
sorry and thank you for pointing that out. basically the current script enables you to login to a single device, execute a backupconfig and send it to the designated tftp server.

I would however want this to have more function like, being able to execute the command to a series/list of devices
 
Old 11-24-2015, 03:13 AM   #5
rd700
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ilesterg View Post
Welcome to the forums!

Please take time to read this sticky.

For readability's sake, please wrap your commands in [ CODE ] tags. We don't want to drive people away just by irritating their eyes with unformatted commands.

thanks for the heads up, will visit the link..
 
Old 11-24-2015, 03:26 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by rd700 View Post
sorry and thank you for pointing that out. basically the current script enables you to login to a single device, execute a backupconfig and send it to the designated tftp server.

I would however want this to have more function like, being able to execute the command to a series/list of devices
You probably would benefit from looking at an existing tool like ansible.

But either way, it would be easier to work with key-based authentication and keep the keys in an agent so you can skip most of the expect stuff. For what it's worth, you can even tie a key to a specific program or script so that it does just that one thing.
 
2 members found this post helpful.
Old 11-24-2015, 05:24 AM   #7
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,623

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
ssh-copy-id is key

I second Turbo. I work on an ASP environment with MANY application servers. I can start the same command on all of them within seconds, using nothing but a myhosts file (list of the servers) and a small script that loops through calling ssh to remote the command. Once keys are set up, this is easy.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] expect + ssh through proxy host weirdness nitrohuffer2001 Programming 4 08-18-2015 06:45 PM
Problems with an Expect script SSH into multiple hosts in a loop gdizzle Programming 6 01-22-2015 08:13 PM
passing multiple argument to expect script sumeet inani Linux - Newbie 11 05-06-2014 08:12 AM
Using expect for ssh in a script massy Programming 4 03-24-2014 11:42 AM
Expect script to ssh a switch hasan_sust Linux - Newbie 4 09-15-2009 10:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration