Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 159

expect with bash for ssh and ping to remote server

$
0
0

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


Viewing all articles
Browse latest Browse all 159

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>