Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #! /bin/zsh
  2. # 从远程服务器下载文件
  3. # 基于scp
  4. # 传入路径
  5.  
  6. s_info=('IP1' 'IP2')
  7. u_info=用户名
  8. bastion_ip='跳板机IP'
  9. bastion_port=跳板机端口
  10. reply_info='-JUMPER-0'
  11. rsa_path='/Users/用户名/.ssh/server_id_rsa'
  12.  
  13. # 下载文件路径
  14. target_file=$1
  15.  
  16. if [ -z "$target_file" ]; then
  17. echo "请传入需要下载的文件"
  18. return
  19. fi
  20.  
  21. echo "\n\n"
  22.  
  23. print $s_info
  24.  
  25. echo -n "Enter Server No.:"
  26. read s_no
  27.  
  28. if [ -z "$s_no" ]; then
  29. s_no=1
  30. fi
  31.  
  32. l_info=$s_info[$s_no]
  33.  
  34. set timeout 10
  35.  
  36. /usr/bin/expect <(cat << EOF
  37. spawn ssh -A -p ${bastion_port} -i ${rsa_path} ${u_info}@${bastion_ip}
  38. expect "${u_info}(0)@*${reply_info}*"
  39. send "scp -P $bastion_port $u_info@$l_info:$target_file /home/$u_info/\r"
  40. expect "*${send_file}*100\%*"
  41. send "exit\r"
  42. expect "Connection to * closed."
  43. EOF
  44. )
  45.  
  46. file_name=${target_file##*/}
  47. scp -P $bastion_port -i $rsa_path $u_info@$bastion_ip:/home/$u_info/$file_name ./;
  48.  
  49. echo "\n\n"
  50.  
  51. echo "~~${target_file}已下载到当前目录~~";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement