Created
May 19, 2015 14:44
-
-
Save sathishvj/ab63eb888b1354056073 to your computer and use it in GitHub Desktop.
scp a file to a known location on servers based on a part entry from /etc/hosts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to scp a file to the /home/ec2-user/transfers dir | |
function scpxfer() { | |
file="$1" | |
if [ ! -f "$file" ]; then | |
echo "Error! Given file $file does not exist! Exiting" | |
return 1 | |
fi | |
sshSrvr="$2" | |
count=`cat /etc/hosts | grep $sshSrvr | wc -l` | |
if [ $count -ne 1 ]; then | |
echo "More than one /etc/hosts entry that matches the string" $sshSrvr | |
ho $sshSrvr | |
else | |
srvr=`cat /etc/hosts | grep $sshSrvr | sed -e "s/[[:space:]]\{1,\}/ /g" | cut -f2 -d " "` | |
echo "Transferring to $srvr" | |
scp "$file" ec2-user@"$srvr":/home/ec2-user/transfers | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment