gitlink_runner_ssh/script/ssh_expect

32 lines
704 B
Plaintext
Executable File

#!/usr/bin/expect
set timeout -1
set remote_user ${JIANMU_REMOTE_USER}
set remote_host ${JIANMU_REMOTE_HOST}
set remote_port ${JIANMU_REMOTE_PORT}
set ssh_cmd ${JIANMU_SSH_CMD}
set gateway_user ${JIANMU_GATEWAY_USER}
set gateway_host ${JIANMU_GATEWAY_HOST}
set gateway_port ${JIANMU_GATEWAY_PORT}
# 登录跳板机
spawn ssh -p $gateway_port $gateway_user@$gateway_host
expect {
"yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$gateway_password\r" };
"*$ " {
send "ssh -p $remote_port $remote_user@$remote_host $ssh_cmd\r"
expect {
"yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$remote_password\r" };
"*$ " {send "exit\r"}
}
}
}