Skip to content

Instantly share code, notes, and snippets.

@BackFront
Created April 15, 2016 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BackFront/38ae2b4b4736dd86528a6094774e01a3 to your computer and use it in GitHub Desktop.
Save BackFront/38ae2b4b4736dd86528a6094774e01a3 to your computer and use it in GitHub Desktop.
Script auxilio para envio entre local para servidor linux
#!/bin/bash
### Set Language
### Set default parameters
if [ "$(whoami)" != 'root' ]; then
echo $"You have no permission to run $0 as non-root user. Use sudo"
exit 1;
fi
pacote=$(dpkg --get-selections | grep "^expect" )
if [ -n "$pacote" ] ;
then echo
echo "Start..."
else echo
echo "'sshpass' packege is necessery."
echo "install Expect? (Y/N)"
read install_pack
case $install_pack in
"Y")
sudo apt-get install expect
;;
"N")
exit
;;
esac
fi
echo "==================================================================="
echo "========================== Automatic SCP =========================="
echo "==================================================================="
echo "* Powered by: Douglas Alves <alves.douglaz@gmail.com>"
echo "* Version: 1.0"
echo "_________________"
echo "Select an option:"
echo
echo
echo
echo
echo "[0] - Sendfile: host => local"
echo "[1] - Sendfile: local => host"
echo "------------------------------------------------------------------"
echo
echo
echo
echo
read option;
case $option in
0)
set timeout 60
echo "SSH user:"
read ssh_user;
echo ""
echo "SSH password:"
# stty -echo
# read ssh_password;
# stty echo
echo ""
echo "SSH host:"
read ssh_host;
echo ""
echo "SSH port (NULL to use default):"
read ssh_port;
echo ""
echo "SSH path/file:"
read ssh_path;
echo ""
echo "Local path/file:"
read local_path;
R1="$ssh_user@$ssh_host"
scp -P $ssh_port -r $local_path $R1:$ssh_path
expect "$ssh_user@$ssh_host's password:"
send ""
;;
1)
echo "SSH user:"
read ssh_user;
echo ""
# echo "SSH password:"
# stty -echo
# read ssh_password;
stty echo
echo ""
echo "SSH host:"
read ssh_host;
echo ""
echo "SSH port (NULL to use default):"
read ssh_port;
echo ""
echo "SSH path/file:"
read ssh_path;
echo ""
echo "Local path/file:"
read local_path;
R1="$ssh_user@$ssh_host"
scp -P $ssh_port -r $local_path $R1:$ssh_path
expect "$ssh_user@$ssh_host's password:"
send ""
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment