Results 1 to 6 of 6
  1. #1
    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

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,015
    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.

  3. #3
    Join Date
    Dec 2012
    Posts
    53
    Thanks for your reply.

    I want some corn job to do this

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,015
    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

  5. #5
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,681

    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

  6. #6
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,015
    That's true, but as you can see there are other more interesting corn jobs
    http://www.francesfarmersrevenge.com...cmoonshine.jpg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •