Advertisement
Guest User

Untitled

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