52 lines
1.3 KiB
Plaintext
Executable File
52 lines
1.3 KiB
Plaintext
Executable File
#!/usr/bin/expect
|
|
set timeout -1
|
|
set local_file ${JIANMU_LOCAL_FILE}
|
|
set remote_user ${JIANMU_REMOTE_USER}
|
|
set remote_host ${JIANMU_REMOTE_HOST}
|
|
set remote_port ${JIANMU_REMOTE_PORT}
|
|
set remote_password ${JIANMU_REMOTE_PASS}
|
|
set remote_file ${JIANMU_REMOTE_FILE}
|
|
|
|
set gateway_user ${JIANMU_GATEWAY_USER}
|
|
set gateway_host ${JIANMU_GATEWAY_HOST}
|
|
set gateway_port ${JIANMU_GATEWAY_PORT}
|
|
set gateway_password ${JIANMU_GATEWAY_PASS}
|
|
set temp_file ${JIANMU_TEMP_FILE}
|
|
|
|
# 上传文件到跳板机
|
|
spawn scp -P $gateway_port -r $local_file $gateway_user@$gateway_host:~/$temp_file
|
|
|
|
expect {
|
|
|
|
"yes/no" { send "yes\r"; exp_continue }
|
|
|
|
"*password:" { send "$gateway_password\r" };
|
|
|
|
}
|
|
|
|
# 登录跳板机
|
|
spawn ssh -p $gateway_port $gateway_user@$gateway_host
|
|
expect {
|
|
|
|
"yes/no" { send "yes\r"; exp_continue }
|
|
|
|
"*password:" { send "$gateway_password\r" };
|
|
|
|
"*$ " {
|
|
# 从跳板机复制文件到目标主机
|
|
send "scp -P $remote_port -r $temp_file $remote_user@$remote_host:~/$remote_file\r"
|
|
expect {
|
|
"yes/no" {
|
|
send "yes\r"
|
|
exp_continue
|
|
}
|
|
"*password:" {
|
|
send "$remote_password\r"
|
|
}
|
|
"*$ " {
|
|
send "rm $temp_file\r"
|
|
expect "*$ " {send "exit\r"}
|
|
}
|
|
}
|
|
}
|
|
} |