-   Slackware (
-   -   Crond script doesn't work as expected (

Karimo 02-14-2010 05:25 PM

Crond script doesn't work as expected
Hi everybody!
I'm posting here because, having a long time surfing the internet I still don't have a solution to my issue.
The script does a backup of a specific directory once a day, deleting the oldest backups if they are more than 31.
The script run perfectly executed from console, but under crond it create correctly the backup but not seems to delete the in-excess backups.


/usr/bin/tar cfj /root/condivisa_backups/polizze_`/usr/bin/date | /usr/bin/sed s/\ /_/g`.tar.bz2 /mnt/hd/condivisa/GRUPPO\ POLIZZE 2>/dev/null
/usr/bin/ls -lt /root/condivisa_backups/polizze_* | /usr/bin/gawk 'BEGIN { a=0 } { a++; if (a>31) { system("/usr/bin/rm -f "$8); } }'

As you can see, is the second line that seems not be executed at all.
I really don't understand the reason.
Thank you for helping me,


unSpawn 02-14-2010 06:32 PM

Why use "/root" for backups? And why add the date that way when you can use easier sorting with just

TARDATE=$(date +%Y%m%d); tar -cjf /backupmountpoint/condivisa_backups/polizze_${TARDATE}.tar.bz2 /mnt/hd/condivisa/GRUPPO\ POLIZZE >/dev/null 2>&1
Using 'ls' for feeding output usually isn't the best of solutions. Why not use 'find':

find /backupmountpoint/condivisa_backups/ -type f -iname polizze_\* -atime +31 -print0|xargs -0 echo rm -f
(BTW when testing it's best not to use 'rm' but 'echo' files instead.)

All times are GMT -5. The time now is 07:22 PM.