Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/zsh
- # 从远程服务器下载文件
- # 基于scp
- # 传入路径
- s_info=('IP1' 'IP2')
- u_info=用户名
- bastion_ip='跳板机IP'
- bastion_port=跳板机端口
- reply_info='-JUMPER-0'
- rsa_path='/Users/用户名/.ssh/server_id_rsa'
- # 下载文件路径
- target_file=$1
- if [ -z "$target_file" ]; then
- echo "请传入需要下载的文件"
- return
- fi
- echo "\n\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 $u_info@$l_info:$target_file /home/$u_info/\r"
- expect "*${send_file}*100\%*"
- send "exit\r"
- expect "Connection to * closed."
- EOF
- )
- file_name=${target_file##*/}
- scp -P $bastion_port -i $rsa_path $u_info@$bastion_ip:/home/$u_info/$file_name ./;
- echo "\n\n"
- echo "~~${target_file}已下载到当前目录~~";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement