-
-
Save cowens/10478652 to your computer and use it in GitHub Desktop.
Simple wrapper for scp to add : on the end of known and suspected hosts
This file contains hidden or 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
#!/bin/bash | |
SCP=/usr/bin/scp | |
declare -a hosts=( | |
host1 | |
host2 | |
host3 | |
) | |
declare -a args=( "$@" ) | |
if [[ ${#args} -gt 1 ]]; then | |
last_arg=${args[-1]} | |
# if there isn't a colon in the last argument, | |
# then we might need to add one | |
if [[ "$last_arg" != *:* ]]; then | |
add_colon=no | |
# if it has an @, then it is likely user@host, | |
# so we need to add one | |
if [[ "$last_arg" == *@* ]]; then | |
add_colon=yes | |
else | |
# otherwise, if last arg is a known host, | |
# then add a : | |
for host in "${hosts[@]}"; do | |
if [[ "$host" == "$last_arg" ]]; then | |
add_colon=yes | |
break | |
fi | |
done | |
fi | |
if [[ $add_colon == "yes" ]]; then | |
args[${#args[@]} - 1]="$last_arg:" | |
fi | |
fi | |
fi | |
exec $SCP "${args[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment