Skip to content

Instantly share code, notes, and snippets.

@cowens
Last active August 29, 2015 13:59
Show Gist options
  • Save cowens/10478652 to your computer and use it in GitHub Desktop.
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
#!/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