Skip to content

Instantly share code, notes, and snippets.

@RitterHou
Created September 19, 2020 16:41
Show Gist options
  • Save RitterHou/dc17ca84bf22e0c4ca9287d1c33721d2 to your computer and use it in GitHub Desktop.
Save RitterHou/dc17ca84bf22e0c4ca9287d1c33721d2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
flag="to"
while getopts ":l:r:u:h:f:" opt; do
case $opt in
l) local="$OPTARG"
;;
r) remote="$OPTARG"
;;
u) user="$OPTARG"
;;
h) host="$OPTARG"
;;
f) flag="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG"
;;
esac
done
if [ "$flag" == "to" ]; then
rsync -avzhP -e 'ssh -p 22' "$local" "$user"@"$host":"$remote"
else
rsync -avzhP -e 'ssh -p 22' "$user"@"$host":"$remote" "$local"
fi
# ./sync.sh -u lighthouse -h fun.hourui.me -l /Users/hourui/Downloads -r /home/lighthouse/fun/index.html -f from
# ./sync.sh -u lighthouse -h fun.hourui.me -l /Users/hourui/tmp/Conan.mp4 -r /home/lighthouse/fun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment