Попробуйте это
#redirect stderr to null
exec 2> /dev/null
FILECOUNT = `find *.log -mtime +1|wc -l`
#redirection of stderr to file
exec 2> /tmp/errors.txt
# gzip old log files
if [ $FILECOUNT != '0' ]; then
find *.log -mtime +1|xargs gzip -f
fi
# test if error log file is empty
if [ -s /tmp/errors.txt ]; then
.....
fi`
Если вы используете GNU-версию xargs, вы можете использовать -r
:
--no-run-if-empty
-r If the standard input does not contain any nonblanks, do not run
the command. Normally, the command is run once even if there is
no input. This option is a GNU extension.
Код:
# redirection of stderr to file
exec 2> /tmp/errors.txt
# gzip old log files
find *.log -mtime +1|xargs -r gzip -f
# test if error log file is empty
if [ -s /tmp/errors.txt ]; then
.....
fi