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.
Do anyone know how to solve this problem?
I’d get rid of
exec 2> /tmp/errors.txt for file in *.log; do gzip -f $file done if [ -s /tmp/errors.txt ]; then
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.