I have directories in my home folder that hold reports uploaded via FTP. The daily folders are named like YYYYMMDD. At 00:01, I want to delete the folder from four days ago. At 01:01, I want to change the access to 755 on the previous day's folder.
The statements work when entered on the command-line, but not from root's cron. I tried using find
, but I got the same behavior. The single line python statement is preferable because I don't need to scan the entire folder; this is on a model b, so using find
is slow, and unnecessary since I know exactly what I want to work with.
rm -rf /home/me/reports/`/usr/bin/python -c 'import datetime; print (datetime.datetime.now()+datetime.timedelta(days=-4)).strftime("%Y%m%d")'`
chmod -R 755 /home/me/reports/`python -c 'import datetime; print (datetime.datetime.now()+datetime.timedelta(days=-1)).strftime("%Y%m%d")'`
These are the lines from root's crontab:
1 0 * * * rm -rf /home/me/reports/`/usr/bin/python -c 'import datetime; print (datetime.datetime.now()+datetime.timedelta(days=-4)).strftime("%Y%m%d")'`
1 1 * * * chmod -R 700 /home/me/reports/`/usr/bin/python -c 'import datetime; print (datetime.datetime.now()+datetime.timedelta(days=-1)).strftime("%Y%m%d")'`
sudo crontab -l | egrep -v '^#'
chmod 755
orchmod 700
. Also, since you're usingchmod -R
, you're marking all your reports as executable scripts. Perhaps you wantchmod -R go-rw
(revoke group's and others' read and write permissions for the directory and everything in it) instead?