Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Expect /bash, 2 ssh login users


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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
Login or Register to Reply

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

More UNIX and Linux Forum Topics You Might Find Helpful
Expect script ssh passwordless login
tdubb123
how can i use an expect script to do a passwordless ssh login and run a script on a bunch of remote hosts? I do not want to use public key authentication as this would require me to setup the keys on the clients etc....... Shell Programming and Scripting
2
Shell Programming and Scripting
How to set PATH variable for all HP-UX users when they login using ssh?
prvnrk
Hello friends, I need to set PATH variable for all HP-UX users. I tried to implement it using /etc/profile and /etc/sshrc both none of them work. I don't see sshrc file anywhere. Please advise! TIA... HP-UX
4
HP-UX
RHEL: Users unable to login via SSH
titanic4u
removing the post... Red Hat
6
Red Hat
bash, ssh and expect to multiple ip addresses
marko07
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...... Shell Programming and Scripting
2
Shell Programming and Scripting
Not able to login as normal users through console /telnet/ssh
mnkfre
Hi , I am having problem,users are not able to login through ssh or telnet.Only we can login as root user in console. Restarted telnet and sshd ,no luck. Any ideas. AIX -- 5.2 ML 07 Thanks, MNK... AIX
1
AIX

Featured Tech Videos