Cisco, 2 ssh logins for expect /bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cisco, 2 ssh logins for expect /bash
# 1  
Old 09-10-2018
Cisco, 2 ssh logins for expect /bash

HI all
i need to connect to about 900 cisco routers and switch to do some configs changes. the issue i am having is that half the devices have one set of username and password and the other half have another username and password. From expect or bash script i can ssh into a device and make changes. I need a sript that will try and ssh into the device with user 1 and password, if it fails it must try and ssh with user2 name and password.

I am new to expect and bash, explination and help will greatly be appreciated.
my expect script so far:

Code:
#!/usr/bin/expect -f
# Define the input variable, this will be a routername.domain-name
set host "x.x.x.x" 
set timeout 8
# Define the login credentials we will use.
set username "xxxx" 
set password "!xxxx123" 
set usernamessh "eeeeee" 
set passwordssh "eeee123" 
# Ssh to host ip address
spawn ssh -q -o StrictHostKeyChecking=no $username@$host

expect {
timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
eof { send_user "\nSSH failure for $hostname\n"; exit 1 }
"*assword"
}
# Send password if ssh is succesfull
send "$password\r"
# If Prompts *# not found, return login failed
expect {
timeout { send_user "\nLogin failed. Password incorrect.\n"; exit 1}
"*#"
}
interact

Moderator's Comments:
Mod Comment Please use code tags or face the wrath of Sauron.


# from here i need to add second ssh attempt to
#login to device using the second username and password..if
# the first ssh failed. please help i have no idea what to do now.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Ubuntu

Expect /bash, 2 ssh login users

HI all i need to connect to about 900 cisco routers and switch to do some configs changes. the issue i am having is that half the devices have one set of username and password and the other half have another username and password. From expect or bash script i can ssh into a device and make... (1 Reply)
Discussion started by: quintin
1 Replies

2. Windows & DOS: Issues & Discussions

Fail2ban: email notifications and banning ssh IP logins

Hi all. I am using Cygwin in Windows 7 and am trying to setup fail2ban so that I can ban foreign IP addresses under SSH, also getting email notifications. I downloaded fail2ban and installed it. I then created jail.local copy from jail.conf and changed some values in jail.local. Now when I try to... (2 Replies)
Discussion started by: synthesis
2 Replies

3. Red Hat

Limit root user of SSH logins

Hi team, I tried to modify the /etc/security/limits.conf file to limit the root user for more one login. I added the line in limits.conf file like: @root hard maxlogins 1 I also tried to modify /etc/ssh/sshd_config to limit the root userlogin by adding this: ... (10 Replies)
Discussion started by: leo_ultra_leo
10 Replies

4. Shell Programming and Scripting

Expect script to show cisco configs

I know there are better ways to do this. I prefer snmp. I do not have the proper perl modules loaded on the platorm. Snmp isnt loaded on the platform. Telnet is not an option. I need to write an expect script to pull cisco equipment configs. The following code is executed once I gain... (0 Replies)
Discussion started by: popeye
0 Replies

5. Shell Programming and Scripting

Bash script failed with expect on cisco routers

Hi all, I use a bash script which use expect to connect throught ssh and run command on a cisco router. The ssh connection with expect work fine, but the first command on the cisco router failed, I try to run the command in error by hand and it work fine... :( the first part of the script... (2 Replies)
Discussion started by: bedomon
2 Replies

6. Solaris

Display logins via SSH

For work, I need a box to show all logins made recently upon a successful login. Sort of a banner showing previous logins. Not sure how to go about this. (2 Replies)
Discussion started by: LittleLebowski
2 Replies

7. Shell Programming and Scripting

Expect/telnet/testing tacacs on a cisco

At times I find the need to test that the tacacs port 49 is open. The code below works but is painfully slow because I have to wait on the timeouts. Examples of possible responds router1#telnet 10.11.20.14 49 Trying 206.112.204.140, 49 ... Open route1#telnet 10.11.19.14 49 Trying... (1 Reply)
Discussion started by: popeye
1 Replies

8. Shell Programming and Scripting

bash, ssh and expect to multiple ip addresses

Hi, I need script that will allow me to connect to multiple clients using ssh on Ubuntu terminal... I have a txt file with the ip addresses of clients, i need a script that will connect to everyone one by one and send some commands... The idea is to check some settings on every client... (2 Replies)
Discussion started by: marko07
2 Replies

9. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies
Login or Register to Ask a Question