![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Backup my files to DAT | jefferson | UNIX for Dummies Questions & Answers | 1 | 09-30-2007 07:13 PM |
| Counting Files and send an email Notification if it exceeds a limit | amitsayshii | UNIX for Dummies Questions & Answers | 10 | 07-07-2006 07:25 AM |
| backup files for a specific month | problems | Shell Programming and Scripting | 3 | 04-28-2006 12:53 AM |
| limit to number of files in a given directory | hedrict | UNIX for Advanced & Expert Users | 2 | 02-05-2004 01:14 PM |
| limit of files in the ufs filesystem | witt | UNIX for Dummies Questions & Answers | 2 | 06-25-2002 07:02 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Limit backup files
Hello all,
I am building a shell script. Every morning my shell script will trigger an external system backup script and the backup file (File Name format: "20030929backup.bkp" (i.e)current date + "backup.bkp") will be stored in the backup directory. After successful back, I need to keep only 10 backup files in the backup folder at most. Say on 11th day, day 1 file should be deleted and the 11th day file should be created. What's the best way to do this? I am using the below command to get the list of backup files from backup directory. $ find /home/EBI -name "*.bkp" -exec ls {} \; We need to calculate the calendar days. I thought of using (-atime +10) but, the thing is this backup script will not run on Sundays. So we miss one day... I guess we may need to count the number of backup files, find the oldest one, delete it and add the current file. What's the simple way to do this? Thanks. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Try this:
rm `ls -tr *.bkp | head -1` |
|
#3
|
|||
|
|||
|
But, how do I count 10 backup files? and if it exceeds 10 then your command will work to delete the oldest file.
Thanks |
|
#4
|
||||
|
||||
|
I thought that you wanted to delete the oldest file. At this point I don't know what you want. But I'll take a stab at this anyway...
You can count backup files with: ls *.bkp | wc -l And this technique will indeed work if you happen to have 10 backup files. |
|
#5
|
|||
|
|||
|
Thanks Perderabo. It worked.
|
|
#6
|
|||
|
|||
|
Also, I am trying to send an e-mail notification at the end of this script and I am using
$ /usr/lib/sendmail -v toname@name.com < /home/lognotes.txt How do I specify the subject field? Also, Is there a way I can type the message body instead of sending the log file from the command itself. Just simple one line command with "Subject", "To", "message body" I want to send an e-mail like this: ******************************************* From: from@name.com To: toname@name.com Subject: Notification Message Body: Backup Success ******************************************* Please help, Thanks, -Jai |
|
#7
|
||||
|
||||
|
You need to use a user agent rather than calling sendmail directly. Or you need to make your script smart enough to actually be a user agent.
You may have user agents named things like elm or mailx. I would use mailx and then the subject is specified with -s. |
||||
| Google The UNIX and Linux Forums |
| Tags |
| mailx, mailx attachment, sendmail |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|