If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > script to delete old files in file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Dec 2012
Posts: 53
script to delete old files in file

Hi i am new to scripiting, please help me
My requirment is

Every day some logs files will be archived to some location, i need to keep only 10 day files in that archive path .
For Example- on 29-1-2013 only log files from 19-1-2013 to 29-1-2013 should be there , It should run every-day suppose on 30th there should be logs from 20th only.

please help me with script and any links to down load the documents
Reply With Quote
  #2 (permalink)  
Old
Programming since 1BC
 
Join Date: Sep 2009
Location: Ontario
Posts: 972
Code:
cd directory_containing_log_files
find ./ -mtime +10 -exec delete.logfile.script {} \;
Code:
#delete.logfile.script
echo Delete $1
rm $1
You can embellish as necessary.
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Dec 2012
Posts: 53
Thanks for your reply.

I want some corn job to do this
Reply With Quote
  #4 (permalink)  
Old
Programming since 1BC
 
Join Date: Sep 2009
Location: Ontario
Posts: 972
Quote:
some corn job
There are no corn jobs, there are however Korn shell scripts, and there are also cron jobs, which are scheduled tasks.

Code:
#!/bin/ksh       #specify the Korn shell
cd log_directory
find ./ -mtime +10 -exec rm {} \;
Add the following line to the cron file for whichever user is going to run the job.
Code:
0 23 * * * /home/user/delete_log_script >/home/user/delete_log_script.log 2>&1
This line will run your script at 11pm every day and create a log of the script's activity.
You really need to read the following:
man cron
man crontabs
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,657
Talking Corn Jobs

Quote:
Originally Posted by kitaman View Post
There are no corn jobs, there are however Korn shell scripts, and there are also cron jobs, which are scheduled tasks.
Wrong... check this out: Corn Jobs
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #6 (permalink)  
Old
Programming since 1BC
 
Join Date: Sep 2009
Location: Ontario
Posts: 972
That's true, but as you can see there are other more interesting corn jobs
http://www.francesfarmersrevenge.com...cmoonshine.jpg
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On