0

私のプログラムでは、多数のリモート システムへの自動ファイル転送が必要です。そこでRSYNC SSHファイル転送にexpectを使ってみました。必要な入力を提供するターミナルを介して、または値を渡す単純な 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 

人間の干渉を必要とせずにファイル転送プロセス全体を完全に自動化するソリューションを提案してください...

前もって感謝します..

4

1 に答える 1