Professional Web Applications Themes

Check older files, their size and compress using either gzip or 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 or gzip depending on the file size -vf done I have asked some comment on this script before. In above script, I'd like to add a ...

  1. #1

    Default Check older files, their size and compress using either gzip or 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 or gzip
    depending on the file size -vf



    done

    I have asked some comment on this script before.

    In above script, I'd like to add a logic to check the file size and
    then decide to use compress if the file size is over 2 GB MB or use
    gzip if the file size is less than 2 GB. I know the recent version of
    gzip can handle files oer 2 GB but it doesn't work on our system yet.
    How can I make it in a single line or two lines?

    Herbert Guest

  2. #2

    Default Re: Check older files, their size and compress using either gzip or compress

    "Herbert" <com> writes: 

    You may find that doing "gzip < $file > ${file}.gz" works on large
    files even when "gzip $file" does not.
     

    Consider using find's "-size" option.

    --
    James Carlson, KISS Network <com>
    Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
    MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
    James Guest

  3. #3

    Default Re: Check older files, their size and compress using either gzip or compress

    2006-01-20, 11:55(-05), James Carlson: 
    >
    > You may find that doing "gzip < $file > ${file}.gz" works on large
    > files even when "gzip $file" does not.[/ref]
    [...]

    Rather cat < "$file" | gzip | cat > "$file.gz"

    gzip may still do some fstats on either stdin or stdout that
    wouldn't be OK on large files, but would if stdin and stdout are
    just pipes.

    --
    Stéphane
    Stephane Guest

  4. #4

    Default Re: Check older files, their size and compress using either gzip or compress

    Stephane CHAZELAS <invalid> writes: 

    "May?"

    --
    James Carlson, KISS Network <com>
    Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
    MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
    James Guest

Similar Threads

  1. compress pdf
    By wouterdebo@gmail.com in forum Adobe Acrobat SDK
    Replies: 0
    Last Post: December 29th, 08:57 AM
  2. HELP!! Compress MPEG files
    By jamieclock in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: April 1st, 11:24 AM
  3. How to get the Windows XP backup program to compress files?
    By Hubert Earl in forum Windows XP/2000/ME
    Replies: 1
    Last Post: July 21st, 03:46 PM

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