Using expect script to do an ssh from a remote machine -


i new expect scripts , have use case in need ssh machine in have done ssh using expect script. code snippet

#!/usr/bin/expect -f set timeout 60 spawn ssh username@machine1.domain.com  expect "password: " send "password\r"  send "\r" # successful. able login first machine  set timeout 60 spawn ssh username@machine2.domain.com  #this fails 

this takes amount of time , fails saying ssh: connect host machine2.domain.com port 22: operation timed out. understand 22 default port on ssh runs , can manually override giving -p option ssh.

if try ssh independently without expect script prompt asks me enter (yes/no). correct port being picked if execute ssh directly without expect script. if not need enter port number on shell why needed enter port number if using expect script.

that point, don't spawn new ssh: spawn creates new process on local machine. send command remote server

#!/usr/bin/expect -f set timeout 60 spawn ssh username@machine1.domain.com  expect "password: " send "password\r"  send "\r" # successful. able login first machine  # @ point, carry on scripting first ssh session: send "ssh username@machine2.domain.com\r" expect ... 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -