Expect /bash, 2 ssh login users

Tags
bash, expect, expect script, ssh, ubuntu, users

 
Thread Tools Search this Thread
# 1  
Old 09-10-2018
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 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

# 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.


Last edited by Scott; 09-10-2018 at 10:07 AM.. Reason: Please use code tags
# 2  
Old 09-10-2018

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Cisco, 2 ssh logins for expect /bash quintin Shell Programming and Scripting 0 09-10-2018 10:09 AM
Automate OTPW login to ssh via bash script instro Shell Programming and Scripting 1 06-12-2015 11:43 AM
Expect script ssh passwordless login tdubb123 Shell Programming and Scripting 2 02-21-2014 03:58 PM
How to set PATH variable for all HP-UX users when they login using ssh? prvnrk HP-UX 4 02-10-2014 09:43 AM
How to create multiple users using expect.? alhazerd Shell Programming and Scripting 1 12-04-2013 07:24 PM
Ssh = ssh expect and keep everything not change include parameter postion yanglei_fage Shell Programming and Scripting 1 12-27-2012 12:34 PM
using expect to switch users in a script esolve Shell Programming and Scripting 1 10-04-2012 04:08 PM
RHEL: Users unable to login via SSH titanic4u Red Hat 6 09-30-2011 01:28 PM
telnet login successful ,but ssh can not login alert0919 HP-UX 2 08-03-2011 01:02 AM
bash, ssh and expect to multiple ip addresses marko07 Shell Programming and Scripting 2 06-22-2010 05:50 PM
could not send commands SSH session with Net::SSH::Expect hansini Shell Programming and Scripting 0 08-28-2009 01:56 AM
BASH ssh login mike909 Shell Programming and Scripting 1 05-06-2009 02:56 PM
bash ssh login script modcan Shell Programming and Scripting 2 06-04-2008 02:39 AM
bash script for ssh login- big_pil Shell Programming and Scripting 5 10-29-2007 01:23 PM
Not able to login as normal users through console /telnet/ssh mnkfre AIX 1 09-11-2006 09:24 AM