zipping a directory when the file count is over $X


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting zipping a directory when the file count is over $X
# 1  
Old 06-16-2009
zipping a directory when the file count is over $X

Hiya,

I've been plugging away at this script and I cant get it to behave as I need.

first off it fails to adhere to the conditions of the file limit, and zips the directory regardless of the file count and secondly, but less important it zips up the entire path not just the directory I'm after.

Been at this for hours and I could use a hand.

tired in glasgow

Code:
 
#!/bin/bash

location_Parent=/path/Parent
location_IMG=/path/IMG
location_AUD=/path/AUD
time_a=20090614-205534

echo zipping and deleting dupes
IMG_CNT_MAX=1000 
cd $location_IMG
 FILECOUNT=$(ls | wc -l)
        if [ $FILECOUNT < $IMG_CNT_MAX ]
        then
        echo "zipping and deleeting dupes";
        cd $location_Parent 
        tar -zcvf $time_a-IMG.tar.gz $location_IMG
        tar -zcvf $time_a-AUD.tar.gz $location_AUD
        
        wait 

        rm -r $location_IMG
        rm -r $location_AUD
            
            else
            echo "Number of files has not yet reached $IMG_CNT_MAX, not ready to archive";
        fi

# 2  
Old 06-17-2009
You're using a string comparison operator in your test statement, replace this line:

Code:
if [ $FILECOUNT < $IMG_CNT_MAX ]

with:

Code:
if [ $FILECOUNT -lt $IMG_CNT_MAX ]

# 3  
Old 06-17-2009
if [ $FILECOUNT < $IMG_CNT_MAX ]
then
echo "zipping and deleeting dupes";
cd $location_Parent
tar -zcvf $time_a-IMG.tar.gz $location_IMG
tar -zcvf $time_a-AUD.tar.gz $location_AUD


wait

rm -r $location_IMG
rm -r $location_AUD

this code actually zips all the path $location_IMG
and $location_AUD

try this

if [ $FILECOUNT -lt $IMG_CNT_MAX ]
then
echo "zipping and deleeting dupes";
cd /path/
tar -zcvf $time_a-IMG.tar.gz IMG*
tar -zcvf $time_a-AUD.tar.gz AUD*


wait

rm -r IMG*
rm -r AUD*

this should work
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Total record count of all the file present in a directory

Hi All , We need one help on the below requirement.We have multiple pipe delimited .txt file(around 100 .txt files) present on one directory.We need the total record count of all the files present in that directory without header.File format as below : ... (8 Replies)
Discussion started by: STCET22
8 Replies

2. Shell Programming and Scripting

Zipping contents without the actual directory

Hi , I want to zip files present in the directories listed under a parent directory without zipping the directory itself my parent directory path is /informatica/DGDMN/PowerCenter1011/server/infa_shared/SrcFiles/OTE/Final_Directory I have the below directories named as 1,2,3,4,5 listed... (9 Replies)
Discussion started by: paul1234
9 Replies

3. UNIX for Dummies Questions & Answers

Zipping the logs of directory

Hi Folks, I have logs at the following location cd /out/app/logs/ now that logs directory contain different types of logs now sometimes i need to do disk clean up activity so i need to zipped the logs can you please advise any command by which all the logs created in this directory are... (2 Replies)
Discussion started by: punpun66
2 Replies

4. UNIX for Dummies Questions & Answers

Deleting a directory and zipping another directory

Hi Folks, I have a directory in unix that is /usr/local/pos contain the folowing directoreis ..that is dir1 dir2 dir3 now I want to delete only dir2 please advise how to remove the directory dir 2 ..that is rm command and how to use it , and second if I want to zip the dir3 please... (1 Reply)
Discussion started by: punpun66
1 Replies

5. Shell Programming and Scripting

Count how many times in every file, strings appeared in a directory.

Hello, I have some files and i want to count how many times a string is appeared in each file. Lets say : #cat fileA stringA sdh stringB stringA #cat fileB stringB stringA sdb stringB stringB I need the output to be something like: (2 Replies)
Discussion started by: @dagio
2 Replies

6. Shell Programming and Scripting

Zipping a directory and extracting to another server.

Hello everyone, I am trying to make a script in KSH that will zip an entire directory but leave out one file in that directory. I then need to send that zipped directory to another UNIX box. I am new to UNIX and would appreciate a good template to study from. (3 Replies)
Discussion started by: BrutalBryan
3 Replies

7. Shell Programming and Scripting

Zipping of file in a different directory

Hi, I am having some problem with a shell script which zip some files. For zipping I have used the following command: find . -name "Test_*" -mtime 0 | zip Test_$(date +"%Y%m%d") -@ I have kept the script in /home/abc directory. It is creating the zip file within the same directory where i... (2 Replies)
Discussion started by: abhishek_510
2 Replies

8. UNIX for Dummies Questions & Answers

Creating a file to count how many files in the directory

hello there i want to creat a file that count how many files i have in the directory. for this i use the command find . -type f | wc -l > 1In1.myfile the problem with this command is that it not update after i add a new file in the directory. Anyone got any ideas how i can... (5 Replies)
Discussion started by: AntiPin
5 Replies

9. UNIX for Dummies Questions & Answers

zipping all the tar files to singlr file in directory

Hi, i have more than 300 tar files in directory and i want to zip all tar files to single file. could anybody tell me the command since i know how to do zip for single tar file: bash-3.00$gzip 2008_11_10.tar bash-3.00$ pwd /oracle1/archivebackup in this directory i have lot files... (2 Replies)
Discussion started by: prakash.gr
2 Replies

10. Shell Programming and Scripting

count file(s) under a specific directory

How do I count number of file in a directory. Here is what I want to do. 1. find total number of file in a directory in variable total 2. ftp all the file 3. ftp_return_code=`grep -c "Transfer complete" $logfile` if then exit 0 else exit -1 fi (6 Replies)
Discussion started by: leemjesse
6 Replies
Login or Register to Ask a Question