Skip to content

Instantly share code, notes, and snippets.

@sathishvj
Created May 19, 2015 14:44
Show Gist options
  • Save sathishvj/ab63eb888b1354056073 to your computer and use it in GitHub Desktop.
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
# 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