Esse script provavelmente fará o que você quiser
#!/bin/bash
#
ritem="$1" # [ user@ ] remotehost : [ / ] remotepath_to_directory
shift
rhost="${ritem/:*}" # Can be remotehost or user@remotehost
rpath="${ritem/*:}" # Can be absolute or relative path to a directory
# Get list of files on remote
#
echo "Looking in $rpath on $rhost" >&2
ssh -n "$rhost" find "$rpath" -maxdepth 1 -type f -print0 |
while IFS= read -r -d $'375871.sh remotehost:remotepath localpath/*
' rfile
do
rkey=$(printf "%s" "$rfile" | tr -d '[:space:]_. -' | tr '[:upper:]' '[:lower:]')
list[${rkey/*\/}]="$rfile"
done
# Get list of files from local and copy to remote
#
ss=0
echo "Considering $*" >&2
for lpath in "$@"
do
test -f "$lpath" || continue
lfile="${lpath/*\/}"
lkey=$(printf "%s" "$lfile" | tr -d '[:space:]_. -' | tr '[:upper:]' '[:lower:]')
# Do we have a match in the map
rfile="${list[$lkey]}"
test -z "$rfile" && rfile="$lfile"
# Copy across to the remote system
echo "Copying $lpath to $rhost:$rpath/$rfile" >&2
rsync --dry-run -av "$lpath" "$rhost":"$rpath/$rfile" || ss=$((ss+1))
done
# All done. Exit with the number of failed copies
#
exit $ss
Exemplo de uso
#!/bin/bash
#
ritem="$1" # [ user@ ] remotehost : [ / ] remotepath_to_directory
shift
rhost="${ritem/:*}" # Can be remotehost or user@remotehost
rpath="${ritem/*:}" # Can be absolute or relative path to a directory
# Get list of files on remote
#
echo "Looking in $rpath on $rhost" >&2
ssh -n "$rhost" find "$rpath" -maxdepth 1 -type f -print0 |
while IFS= read -r -d $'375871.sh remotehost:remotepath localpath/*
' rfile
do
rkey=$(printf "%s" "$rfile" | tr -d '[:space:]_. -' | tr '[:upper:]' '[:lower:]')
list[${rkey/*\/}]="$rfile"
done
# Get list of files from local and copy to remote
#
ss=0
echo "Considering $*" >&2
for lpath in "$@"
do
test -f "$lpath" || continue
lfile="${lpath/*\/}"
lkey=$(printf "%s" "$lfile" | tr -d '[:space:]_. -' | tr '[:upper:]' '[:lower:]')
# Do we have a match in the map
rfile="${list[$lkey]}"
test -z "$rfile" && rfile="$lfile"
# Copy across to the remote system
echo "Copying $lpath to $rhost:$rpath/$rfile" >&2
rsync --dry-run -av "$lpath" "$rhost":"$rpath/$rfile" || ss=$((ss+1))
done
# All done. Exit with the number of failed copies
#
exit $ss
Remova --dry-run
quando estiver satisfeito, pois está funcionando como esperado.