The purpose of the next simple wait script is to get the hostname on the remote computer
Sometimes it is expected that the script will not be able to execute ssh before $ IP_ADDRESS (since the remote machine is not active, etc.)
so in this case the wait for the script will break after 10 seconds (wait time 10), this is normal, but ......
There are two options.
- Expect the script to execute ssh successfully and execute the hostname of the command on the remote computer
- Expect a script break because the wait time is 10 seconds
In both cases, exit is expected.
- in case of a successful wait, ssh breaks after 0.5-1 seconds, but in case of a bad ssh then it will break after 10 seconds.
but I don’t know if the script will expect ssh to execute successfully or not?
Is it possible to determine the wait time? or check that the wait is over because the timeout?
Remember my Linux machine version - Little Red Riding Hood 5.1
Expect script
[TestLinux]# get_host_name_on_remote_machine=`cat << EOF > set timeout 10 > spawn ssh $IP_ADDRESS > expect { > ")?" { send "yes\r" ; exp_continue } > > word: {send $PASS\r} > } > expect > {send "hostname\r"} > expect > {send exit\r} > expect eof > EOF`
Example if we do not have a connection to a remote host
[TestLinux]# expect -c "$get_host_name_on_remote_machine" spawn ssh 10.17.180.23 [TestLinux]
user1121951
source share