Portal Home > Knowledgebase > Articles Database > Compress


Compress




Posted by 3FRSB, 05-14-2014, 10:59 PM
Hi, I'm expert to do bash script. Here is first script. But it's got error. I try to seek folder greater than 100M and put in zip file. test.sh Any idea why? Thanks.

Posted by tbenoit, 05-14-2014, 11:10 PM
Don't use spaces around the equal signs: Don't use this: RESULT = `/usr/bin/du -sm /mnt | awk '$1 > 100'` Use this: RESULT=`/usr/bin/du -sm /mnt | awk '$1 > 100'`

Posted by 3FRSB, 05-14-2014, 11:30 PM
I try to split the compress file. But getting error. File exist it seem not found it.

Posted by tbenoit, 05-15-2014, 12:03 AM
Your RESULT is not providing the proper data. When I run it manually $1 is the size & directory name, which is what you are sending to tar. Since there is no file by the name of the size of the directory the command presents an error. You need to just pass the file/directory names you wish to tar up.

Posted by 3FRSB, 05-15-2014, 12:11 AM
The folder that greate than 100MiB is so many. How i put it script? The folder is generate by system auto everyday. That why i come out with this script. Please advice me.

Posted by tbenoit, 05-15-2014, 08:51 AM
If these files are not expected for your server you should investigate why this is occurring and correct the issue. This is the recommended step over just taring up the files/directories. Especially having files/directories created in /mnt. That is generally not normal for a server. The below provides a modified version of the command that populates the RESULT variable. It will output just the file/directory names in /mnt that are over 100MB:

Posted by Srv24x7, 05-15-2014, 10:06 AM
Hi, Modified a bit and tested. It runs successfully. It find file that are higher than 5 MB in size and archives it. --------- Script --------- [root@new 24x7]# cat test.sh #!/bin/bash RESULT=`/usr/bin/du -sm /24x7/* | awk '$1 > 5'| awk {'print $2'}` DATE=`date +%d%b%Y-%H%M-%S` zip -r -s 128 archive-$DATE.zip $RESULT --------- Execution --------- [root@new 24x7]# ./test.sh adding: 24x7/test1.img (deflated 100%) adding: 24x7/test2.img (deflated 100%) adding: 24x7/test3.img (deflated 100%) --------- Created Archive --------- [root@new 24x7]# ll total 26648 -rw-r--r--. 1 root root 18833 May 16 01:03 archive-16May2014-0103-26.zip



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Help with php program (Views: 503)