Professional Web Applications Themes

Need some comments on a Unix script to remove file and compress - Linux / Unix Administration

Hello, There are 6 files. The files have time stamp like aafile.NOV-12-09, bbafile.NOV-12-09, ccfile.NOV-12-09, ddafile.NOV-12-09, eefile.NOV-12-09, fffile.NOV-12-09 I made a simple script to compress all the files over a month and delete them over 6 months like below. #!/bin/ksh # IMPORT_FILES= "Aafile.* \ Bbafile.* \ Ccfile.* \ Ddafile.* \ Eefile.* \ Fffile.*" # FILE_DIR=/xx/xx # # cd $FILE_DIR for i in $IMPORT_FILES do find ${i} -mtime +30 -type f -print0 | xargs -0 compress -vf find ${i} -mtime +180 -type f -print0 | xargs -0 rm -vf done There are other files in the directory but I want to compress ...

  1. #1

    Default Need some comments on a Unix script to remove file and compress

    Hello,

    There are 6 files. The files have time stamp like
    aafile.NOV-12-09,
    bbafile.NOV-12-09,
    ccfile.NOV-12-09,
    ddafile.NOV-12-09,
    eefile.NOV-12-09,
    fffile.NOV-12-09

    I made a simple script to compress all the files over a month and
    delete them over 6 months like below.

    #!/bin/ksh
    #
    IMPORT_FILES= "Aafile.* \
    Bbafile.* \
    Ccfile.* \
    Ddafile.* \
    Eefile.* \
    Fffile.*"
    #
    FILE_DIR=/xx/xx
    #
    #
    cd $FILE_DIR

    for i in $IMPORT_FILES
    do

    find ${i} -mtime +30 -type f -print0 | xargs -0 compress -vf
    find ${i} -mtime +180 -type f -print0 | xargs -0 rm -vf

    done

    There are other files in the directory but I want to compress those 6
    files over a month (actually many files with the same name but with
    different time stamp) and delete them over
    6 months.

    Any comments will be highly appreciated. Any other way to do this?

    Thanks
    Herbert

    Herbert Guest

  2. #2

    Default Re: Need some comments on a Unix script to remove file and compress

    Herbert wrote: 
    .... 

    Typo note - They are capitalized here but not above.
     

    I would rather use the find's to drive the loops rather than use the
    loops to drive the find's:

    find . \( -name "aafile*" -o -name "bbfile*" ... \) -mtime +30 -print
    while read victim ; do
    compress -vf ${victim}
    done

    and then repeat with the 180.

    Just checking since it's been a long time since I switched from
    compress
    to gzip - Compressing preserves mtime, right?

    Doug Guest

  3. #3

    Default Re: Need some comments on a Unix script to remove file and compress

    I am new to Unix. What is the big difference? If the number of files
    that I'd like to handle in the future change, I have to change find
    command (kind of hard coded). I'd like to use just one find command to
    do both for +30 and +180. Is it possible to do it?

    Many thanks

    Herbert Guest

  4. #4

    Default Re: Need some comments on a Unix script to remove file and compress

    On 18 Dec 2005 17:21:31 -0800, Herbert wrote: 

    I would have thought a +30 would pick up a +180.

    Then there is the concept of for loops. Short example

    for _offset in 30 180
    do
    find -atime +${_offset} ...
    done
    Bit Guest

  5. #5

    Default Re: Need some comments on a Unix script to remove file and compress

    > Hello,

    [snip] 

     

    This script doesn't check that if has in fact changed
    directory. It could, potentially, commence operations from
    the root of your directory tree.

    David Guest

  6. Moderated Post

    Default Re: Need some comments on a Unix script to remove file and compress

    Removed by Administrator
    Doug Guest
    Moderated Post

  7. #7

    Default Re: Need some comments on a Unix script to remove file and compress

    How do I check it? Could you let me know please?

    Herbert Guest

  8. #8

    Default Re: Need some comments on a Unix script to remove file and compress

    On 20 Dec 2005 11:32:25 -0800, Herbert <com> wrote: 

    Nobody knows what or who you are responding to, because you didn't
    include any context. Let me guess: you use google to post.

    Dave Guest

Similar Threads

  1. Sample script to remove line breaks in a XML file
    By yann.pambou@gmail.com in forum PERL Modules
    Replies: 0
    Last Post: November 21st, 01:16 AM
  2. how to remove the spaces from a unix file.
    By jagadish in forum Linux / Unix Administration
    Replies: 8
    Last Post: November 9th, 03:27 PM
  3. Remove Comments: /* */, //, & #
    By W. D. in forum PHP Development
    Replies: 1
    Last Post: May 3rd, 09:30 AM
  4. Unix alias command in script file
    By Christine Leseigneur in forum Mac Applications & Software
    Replies: 1
    Last Post: June 26th, 10:03 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139