I'm executing a command like the following to several different systems:

$ rsync -a -v foo@machine.company.com:'/path/to/first/*.log path/to/second.txt' /dest/folder/0007/.

Sometimes *.log does not exist, and that's OK, but rsync generates the following error:

receiving file list ... rsync: link_stat "/path/to/first/*.log" failed: No such file or directory (2)
done

Is there any way to suppress that? The only way I can think of is to use include and exclude filters, which just seem a PITA to me. Thanks!

link|improve this question

57% accept rate
feedback

1 Answer

To clarify, you would just like to not 'see' the error? For that case you could just redirect the Standard Error Output, but you may end up missing a more serious error that you might want to know of.

Redirect Error Output Example

rsync -a -v foo@machine.company.com:'/path/to/first/*.log path/to/second.txt' /dest/folder/0007/ 2>/dev/null

If instead you are looking to only miss the error on a file that doesn't exist, you can't change the rsync *.log filter and you want to avoid using includes, you could wrap it in a script to proceed based on the condition.

Script Example

#!/bin/sh
# Script to Handle Rsync based on Log File Existence
if [ "$(ls -A /path/to/first/*.log > /dev/null > 2&1)" ]; then
     # Log Exists Use This Rsync
    rsync -a -v foo@machine.company.com:'/path/to/first/*.log path/to/second.txt' /dest/folder/0007/
else
    # Log Does Not Exist Use This Rsync
    rsync -a -v foo@machine.company.com:'path/to/second.txt' /dest/folder/0007/
fi

Hope I was some help.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.