By app1mvf
In the below sample of code I am loging into a remote server and checking for the existance of directories… The isse I am having is if the remote server is rebooted then the key would need to be accepted…. I am fully aware that I can bypass the accepting of the key by using “-o StrictHostKeyChecking=no” in conjunction with my ssh command but I would like to add logic whereas I would like the expect script to handle the accepting of the keys dynamicly rather than bypassing…. Using my sample below could someone help me to alter the script below to accept the key when prompted… I would greatly appreaciate all help. Thank you.
#!/bin/bash
rm -f /tmp/expect.result
Directory_List='/tmp/DIR.Drv'
RServer_Task() {
# build the expect script in bash
expect_sh=$(expect -c "
spawn ssh user@192.168.1.172
expect "password:"
send "ABCDEFGr"
expect "#"
send "ls -d $Recr"
expect "#"
send "exitr"
expect "#"
")
# run the expect script
echo "$expect_sh"
}
while read $Rec
do
RServer_Task > /tmp/expect.output
grep 'No such file or directory' /tmp/expect.output >> /tmp/expect.result
done<${Directory_List}
From: http://www.unix.com/shell-programming-scripting/221067-expect-script-accepting-key.html