Periodically deleting old files
-
I spotted this cron job on a dev server.
00 20 1 * * /usr/bin/find . -type f -mtime +30 -exec rm -f {} \;
It's meant to remove files older than 30 days once a month in a particular directory. Problem is that it runs as root. Now there are no files in /root/
root@foo:~# ls -l ~ total 10 drwxr-xr-x 2 root root 6 2013-09-01 20:00 libxml/ drwxr-xr-x 2 root root 6 2013-09-01 20:00 libxslt/ drwxrwxrwx 6 1107 1107 53 2013-09-01 20:00 postgresql-8.4.13/ drwxr-xr-x 19 inet 1000 4096 2013-09-01 20:00 unixODBC-2.3.1/ drwxr-xr-x 7 201 201 100 2013-09-01 20:00 vmware-tools-distrib/ root@foo:~# find ~ -type f /root/.ssh/authorized_keys /root/.bash_history /root/.lesshst root@foo:~#
-
Could have been worse. The kind of nuff-nuff who would put find . in a crontab is probably just as likely to use find / next time. Hell, they're next to each other on the keyboard so they must mean nearly the same thing, amirite?
-
To be fair, all of the OS files in there probably are more than 30 days old, so works-as-coded...
-
@flabdablet said:
Could have been worse. The kind of nuff-nuff who would put find . in a crontab is probably just as likely to use find / next time. Hell, they're next to each other on the keyboard so they must mean nearly the same thing, amirite?
Or, slightly more likely, $TMPDIR/. With the / and without setting TMPDIR.
-
Snoofle is back!
-
@Lawrence said:
Snoofle is back!
Quick, everybody look busy