我的程序需要自动将文件传输到许多远程系统。因此尝试使用 expect 进行 RSYNC SSH 文件传输。当我通过提供必要输入的终端或通过包含传递值的简单 bash 脚本运行.ex文件时,它运行良好。
但是我想在从数据库检查后调用.ex文件通过RSYNC将文件传输到100多台机器,所以我需要通过一些循环运行脚本,动态填充变量......
我的 .ex 文件:
#!/usr/bin/expect -f
set pass [lindex $argv 0]
set server [lindex $argv 1]
set name [lindex $argv 2]
set addr [lindex $argv 3]
set timeout -1
spawn rsync -e "ssh -q -o StrictHostKeyChecking=no" ${addr} ${name}@${server}:/home/deba/
expect {
-re ".*Are.*.*yes.*no.*" {
send "yes\n"
exp_continue
#look for the password prompt
}
"*?assword:*" {
send ${pass}
send "\n"
interact
#The expect command will now return
}
}
我的 Bash 脚本显示错误:
#!/bin/bash
cat /home/deba/content_sync/test/result_remote/sync_Dest_List.txt | while read line2
do
java -cp .:mysql-connector-java-5.1.24-bin.jar Remote_sync_pw_ip_reciever $line2
cat /home/deba/content_sync/test/result_remote/sync_Dest_List.txt | while read line
# this folder contains the arguments for password and server IP separated by space
do
IFS=" " read var1 var2 <<< "$line"
./rsync1.ex $var1 $var2 $line2 /home/deba/cron.sh
done
done
产生的错误:
spawn rsync -e ssh -q -o StrictHostKeyChecking=no /home/deba/cron.sh@deba:/home/deba/
skipping directory .
rsync: mkdir "/home/deba/cron.sh@deba:/home/deba" failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(605) [Receiver=3.0.9]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]
但是从 bash 代码进行的简单调用没有显示任何错误:
#!/bin/bash
./rsync1.ex rups78 10.129.30.44 deba /home/deba/cron.sh
请提出解决方案,以完全自动化整个文件传输过程,而无需任何人为干预...
提前致谢..