Advertisement
Guest User

Untitled

a guest
Apr 16th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #!/bin/bash
  2. ### Set Language
  3. ### Set default parameters
  4. if [ "$(whoami)" != 'root' ]; then
  5. echo $"You have no permission to run $0 as non-root user. Use sudo"
  6. exit 1;
  7. fi
  8.  
  9. pacote=$(dpkg --get-selections | grep "^expect" )
  10.  
  11. if [ -n "$pacote" ] ;
  12. then echo
  13. echo "Start..."
  14. else echo
  15. echo "'sshpass' packege is necessery."
  16. echo "install Expect? (Y/N)"
  17. read install_pack
  18.  
  19. case $install_pack in
  20. "Y")
  21. sudo apt-get install expect
  22. ;;
  23. "N")
  24. exit
  25. ;;
  26. esac
  27. fi
  28.  
  29. echo "==================================================================="
  30. echo "========================== Automatic SCP =========================="
  31. echo "==================================================================="
  32. echo "* Powered by: Douglas Alves <alves.douglaz@gmail.com>"
  33. echo "* Version: 1.0"
  34. echo "_________________"
  35. echo "Select an option:"
  36. echo
  37. echo
  38. echo
  39. echo
  40. echo "[0] - Sendfile: host => local"
  41. echo "[1] - Sendfile: local => host"
  42. echo "------------------------------------------------------------------"
  43. echo
  44. echo
  45. echo
  46. echo
  47.  
  48. read option;
  49.  
  50.  
  51. case $option in
  52. 0)
  53. set timeout 60
  54.  
  55. echo "SSH user:"
  56. read ssh_user;
  57. echo ""
  58. echo "SSH password:"
  59. # stty -echo
  60. # read ssh_password;
  61. # stty echo
  62. echo ""
  63. echo "SSH host:"
  64. read ssh_host;
  65. echo ""
  66. echo "SSH port (NULL to use default):"
  67. read ssh_port;
  68. echo ""
  69. echo "SSH path/file:"
  70. read ssh_path;
  71. echo ""
  72. echo "Local path/file:"
  73. read local_path;
  74.  
  75. R1="$ssh_user@$ssh_host"
  76.  
  77. scp -P $ssh_port -r $local_path $R1:$ssh_path
  78. expect "$ssh_user@$ssh_host's password:"
  79. send ""
  80. ;;
  81.  
  82. 1)
  83. echo "SSH user:"
  84. read ssh_user;
  85. echo ""
  86. # echo "SSH password:"
  87. # stty -echo
  88. # read ssh_password;
  89. stty echo
  90. echo ""
  91. echo "SSH host:"
  92. read ssh_host;
  93. echo ""
  94. echo "SSH port (NULL to use default):"
  95. read ssh_port;
  96. echo ""
  97. echo "SSH path/file:"
  98. read ssh_path;
  99. echo ""
  100. echo "Local path/file:"
  101. read local_path;
  102.  
  103. R1="$ssh_user@$ssh_host"
  104.  
  105. scp -P $ssh_port -r $local_path $R1:$ssh_path
  106. expect "$ssh_user@$ssh_host's password:"
  107. send ""
  108. ;;
  109. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement