Results 1 to 2 of 2
Hi,
I have a script which is logging in to network devices via ssh using expect programming.
My problem is that if I do
Code:
ssh host -l uname
It ...
- 11-13-2009 #1Just Joined!
- Join Date
- Nov 2009
- Location
- Chicago
- Posts
- 7
If and else statement with Expect
Hi,
I have a script which is logging in to network devices via ssh using expect programming.
My problem is that if I do
It only works if y ssh_config is setup to use Protocol 1,2 and my network device I am trying to connect has ssh 1 but not 2. If the network device has ssh 2 but not 1 my script will stop there with an error.Code:ssh host -l uname
Bottom line is I need to apply if and else structure after I try to ssh to see if ssh -1 was successful if not try ssh -2 if not go down hill
Here is my script:
And this is how my script should look like with the proper syntax for expectCode:#!/usr/local/bin/expect -f spawn ssh myHost -l myUsername expect "password:" send "myPassword\r" expect "#" #send "show int status\r" expect "#" send "exit\r"
Thank you in advance.Code:#!/usr/local/bin/expect -f spawn ssh -1 myHost -l myUsername if(not logged in){ ssh -2 myHost -l myUname }else{ echo "it failed\r" } expect "password:" send "myPassword\r" expect "#" #send "show int status\r" expect "#" send "exit\r"
- 11-13-2009 #2Just Joined!
- Join Date
- Nov 2009
- Location
- Chicago
- Posts
- 7
I think I know how to do the if and else structure now I am having different problem.
For some reason after the spawn ssh ip is executed I can't read the result of this command act accordingly in my if and else structure....any ideas?Code:#!/usr/local/bin/expect -f spawn ssh -2 xxx.xx.xxx.xx -l root expect { "password:"{ send "myPw\r" }"*ssh_rsa_verify:*"{ spawn ssh -1 xxx.xx.xxx.xx -l root }"password":{ end "myPw\r" }eof{ exit } } expect "#" #send "show int status\r" send "config t\r" . . some more commands follow
Thank you


Reply With Quote