0

I have developed a script using TCL expect. The use of the script is - if user runs it from server A, it will check sftp file transfer between server B and server C. Below is my code:

#!/usr/bin/expect -f
lassign $argv 1 2
spawn ping -c 2 -i 3 -W 1 $1
expect  {
   " 0%" {puts "Source is rechable!"}
   " 100.0%" {puts "Source is not rechable.Please restart IPSEC and check!";exit 1}
        }
#SSH to remote server $1
spawn ssh -o StrictHostKeyChecking=no root@$1
expect {                
"Password:" {send "password\r";exp_continue}
"*#" {send "ssh successful\r";exp_continue}
   }
send "\n"
#Creating a file in remote server which will be transferred via sftp
send "touch /tmp/mfile\n"
expect "#"
send "chmod 755 /tmp/mfile\n"
expect "#"
#sftp to server$2
spawn sftp -o StrictHostKeyChecking=no root@$2
expect {                
"Password:" {send "Training\r";exp_continue}
"sftp>" {send "sftp successful\r";exp_continue}
       }
send "\n"
#sending remote file
send "put /tmp/mfile\n"
send "\n"
sleep 2
send "File send to Remote Server successfully\n"
expect "sftp>"
send "cd /root/\n"
expect "sftp>"
send "rename mfile mfile_1\n"
expect "sftp>"
#sending back the file
send "get mfile_1 /tmp\n"
expect "sftp>"
sleep 2
send "quit\n"
send "exit\n"

The issue is the file is getting transferred to the Server C from the Server B with this code, but the file is not sent back to Server B. I am yet to add other logic in the code but first wanted to check if the basic code works. Any clue regarding file transfer back would be helpful.

newuser
  • 69
  • 3
  • 14

0 Answers0