Skip to content

Instantly share code, notes, and snippets.

@17twenty
Last active December 11, 2015 00:39
Show Gist options
  • Save 17twenty/4518182 to your computer and use it in GitHub Desktop.
Save 17twenty/4518182 to your computer and use it in GitHub Desktop.
Simple bash script to print out an rsync command for use with copying files from a remote system
#!/usr/bin/env bash
# Simple script to create a pastable rsync command
foo="$(readlink -f "$1")"
# Use everybodys favourite Dynamic IP address checker to get our external IP address.
my_external_ip=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
#echo $my_external_ip
# Add the slashes in to escape stuff
foo=$(echo "$foo" | sed -e 's/ /\\ /g')
foo=$(echo "$foo" | sed -e 's/-/\\-/g')
foo=$(echo "$foo" | sed -e 's/(/\\(/g')
foo=$(echo "$foo" | sed -e 's/)/\\)/g')
boilerplate="rsync -r --progress -h $(whoami)@$my_external_ip:"
echo -e "\e[0;31m$boilerplate\"$foo\" ."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment