I have a custom script which gzip log files when they are one day old. In my script all errors (stderr) are logged to a file and at the end of the script I use this file to know if its execution was good or not.
This part of my code looks like
# redirection of stderr to file
exec 2> /tmp/errors.txt
# gzip old log files
find *.log -mtime +1|xargs gzip -f
# test if error log file is empty
if [ -s /tmp/errors.txt ]; then
.....
fi
My problem is: this code works great if there is at least one file to gzip, but if not it raises an error when I don't want to.
I've tried different solutions to solve this problem with no success.
Does anyone know how to solve this problem?
Try this
If you are using a GNU version of xargs you can use
-r
:Code: