How to remove a dir older than X days?

June 20, 2010 at 10:14:09
Specs: Ubuntu 10.04, embedded GEODE

I want a script on my Ubuntu 10.04 PC that runs automatically at
0:00 every day, and deletes folders inside a specified folder, what
are older than 30 days, then reboot. I've done the schedule thing, it
runs the script every day at 0:00, and this is the script i wrote:

sleep 3
find '/home/camserver/recordings' -type d -mtime +30 -exec sudo
rm -Rf {} \;
sleep 5
sudo reboot
exec ps

I configured linux so it doesnt require a password when entering
sudo mode. So i can use sudo in scripts now, like in the 'find'

I put a few 'sleep' commands in there because i found that it runs
a lot safer with some pauses. But these dont matter... so actually
the 'find' command doesnt work properly. After running the script,
the folders older than 30 days are still there, untouched. Whats
the problem ? (I have 'Thumbs.db' files in all folders (among
videos), because the 'recordings' folder is a shared folder and
others can view it from windows PCs in the house).

any idea ? I think the script looks fine, but then what else can be
the problem ?


See More: How to remove a dir older than X days?

Report •

June 23, 2010 at 07:57:27
I ran into similer problem with Windows Batch Script. I had to do an Attrib -rh on the contents first. I am not sure what the Linux command is, I think it is CHMOD 777 but I would have to look it up.

Look here...

Report •

June 23, 2010 at 09:53:51
Thanks. I already figured it out a different way:

sleep 3
name1tmp=$(date +%m)
name2=$(date +%d)
cd recordings
sudo rm -Rf ?$name
sleep 5
sudo reboot
exec ps

...because the folders inside the 'recordings' folder are named after the date it
was created. like '06-23' in that format. So i figured out to delete the folder
that is one month old. I took the current date, applied some variable math,
then finally i got: 5-23 (if the current date is 06-23). Thats it. I put a wildcard
in there because i got '5-23' in the variable, not '05-23'. But it works pretty

Report •

Related Solutions

Ask Question