shane2peru
August 22nd, 2009, 05:51 AM
Ok, I have a cron job to record an internet radio show that I enjoy. However I manually end up having to go and delete these recorded shows. So I decided to get fancy and write a cron job to remove the old shows. Here is what I have:
0 10 10 * * rm /home/user/location/show-`date +%Y-%m`-0*
0 10 20,21,22 * * rm /home/user/location/show-`date +%Y-%m`-1*
0 10 30,31 * * rm /home/user/location/show-`date +%Y-%m`-2*
ok, I generi-sized that a bit, but you get the idea. Those should work fine, my problem is I get day's 30 and 31 that hang there and collect. So I would like to use the
show-`date +%Y-%m`-3* for the previous month and remove them. I don't really want to write 11 code lines to delete them and crontab it out as that would be excessive. Is there a way to use the previous month in a string format for this type of stuff? Or can the string be used subtracting one month? Or do you have a better idea? I'm no programmer, but have greatly enjoyed learning scripting, so if it can be done with bash it is better, not over my head. :) Thanks.
Shane
0 10 10 * * rm /home/user/location/show-`date +%Y-%m`-0*
0 10 20,21,22 * * rm /home/user/location/show-`date +%Y-%m`-1*
0 10 30,31 * * rm /home/user/location/show-`date +%Y-%m`-2*
ok, I generi-sized that a bit, but you get the idea. Those should work fine, my problem is I get day's 30 and 31 that hang there and collect. So I would like to use the
show-`date +%Y-%m`-3* for the previous month and remove them. I don't really want to write 11 code lines to delete them and crontab it out as that would be excessive. Is there a way to use the previous month in a string format for this type of stuff? Or can the string be used subtracting one month? Or do you have a better idea? I'm no programmer, but have greatly enjoyed learning scripting, so if it can be done with bash it is better, not over my head. :) Thanks.
Shane