LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-14-2010, 05:25 PM   #1
Karimo
Member
 
Registered: Aug 2007
Location: Valencia
Distribution: slackware64-current
Posts: 67

Rep: Reputation: 15
Question 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.

Code:
#!/bin/bash
/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,

Karimo
 
Old 02-14-2010, 06:32 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Why use "/root" for backups? And why add the date that way when you can use easier sorting with just
Code:
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':
Code:
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.)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/sbin/service crond unable to start - gives permission error on /usr/sbin/crond mgervacio Linux - Newbie 6 07-16-2008 01:03 PM
Script cd not work as expected cdcshu Linux - Software 1 11-10-2007 04:38 AM
cron spawning extra crond - script fails jbob75 Linux - Software 2 11-21-2005 04:29 AM
crond wont' work! compu73rg33k Linux - Software 1 08-18-2004 11:40 AM
script does not work with crond michael_util Slackware 3 03-15-2004 02:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 09:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration