I am developing a code. From server, A ssh session will be established to Server B using spawn, and then from Server B sftp file transfer to Server C. Server A and B can be passwordless or it may ask for a password depending upon earlier user configuration. Please find below the code:
#!/bin/bash
/usr/bin/expect <<EOD
lassign $argv 1 2 3 4 file1 file2
spawn ssh -oStrictHostKeyChecking=no root@$1
sleep 2
expect {
"#" {
send_user "successfully logged in!\r"
}
"Password:" {
send "$2\r"
}
}
EOD
sleep 3
pinging=$( ping $3 -w1 | head -n 2 | grep -i time )
if [[ $pinging == *"time"* ]];
then
echo "ping successfull to:" $3
else
echo "ping not successfull:"$3 "Contact IT Support"
exit
fi
The issue is the if-else loop is not getting executed properly for Password prompt or no Password prompt after login to ssh remote session.Its aksing for Password even though login was successful.Also Ping to Server C is working from Server B not from Server A. I am very new to expect TCL commands
<<EOD
by<<'EOD'
. Read the very short section Here Documents inman bash
../testsftp.sh <IP of Server B> <Password of server B> <IP of Server C>