example42/puppi

Daily cronjob: puppi_clean exited with return code 1

mnellemann opened this issue · 5 comments

Hi,

The puppi_clean script returns 1, which makes cron send an email at each run.

When I run the script manually, as shown below, you can see that it executes as expected, but the last 'find' command returns 1 (error).

root@server:~# bash -x /etc/cron.daily/puppi_clean 
+ seconds=360
+ sleep 360
+ '[' /var/log/puppi == / ']'
+ '[' x/var/log/puppi == x ']'
+ find /var/log/puppi -type f -mtime +30 -exec rm '{}' +
+ find /var/log/puppi -type d -mtime +30 -exec rmdir '{}' +
root@server:~# echo $?
1

If I run the last find command manually, you can see that it actually tries to delete the /var/log/puppi directory, which is not empty, hence resulting in the error:

root@server# find /var/log/puppi -type d -mtime +30  -print
/var/log/puppi

A fix could be to change the find command to something like:

find /var/log/puppi/* -type d -mtime +30 -exec rmdir '{}'

Hei, good catch, PR with the suggested fix is welcomed.

Hi,

I'm not allowed to push to master and for some reason I'm not allowed to make a pull request ("Create pull request" button disabled). Should I fork or is there another way ?

Yes, in order to push PR on GitHub you have to fork a repo, make changes in your fork and then you will see the Pull Request button.

Thanks. The fix is tested on Linux (Debian and Ubuntu) and should work for all distros. I'm not sure about *bsd, solaris, etc.

Thank you.