Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/zsh
- # 上传或者下载文件
- # 基于scp
- # 传入路径
- s_info=('IP1' 'IP2')
- u_info=user
- bastion_ip='跳板机IP'
- bastion_port=跳板机端口
- reply_info='-JUMPER-0'
- rsa_path='/Users/user/.ssh/server_id_rsa'
- send_file=$1
- if [ -z "$send_file" ]; then
- echo "请输入要上传的文件"
- return
- fi
- set timeout 10
- /usr/bin/expect <(cat << EOF
- spawn scp -P $bastion_port -i $rsa_path $send_file $u_info@$bastion_ip:/home/$u_info/
- expect "*${send_file}*100\%*"
- send "${send_file}已上传到${bastion_ip}\r"
- EOF
- )
- echo "\n"
- print $s_info
- echo -n "Enter Server No.:"
- read s_no
- if [ -z "$s_no" ]; then
- s_no=1
- fi
- l_info=$s_info[$s_no]
- set timeout 10
- /usr/bin/expect <(cat << EOF
- spawn ssh -A -p ${bastion_port} -i ${rsa_path} ${u_info}@${bastion_ip}
- expect "${u_info}(0)@*${reply_info}*"
- send "scp -P $bastion_port /home/$u_info/$send_file $u_info@$l_info:/home/$u_info/\r"
- expect "*${send_file}*100\%*"
- send "exit\r"
- expect "Connection to * closed."
- EOF
- )
- echo "\n\n~~${send_file}已上传到${l_info}~~\n\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement