Moving file to directory based on condition.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving file to directory based on condition.
# 1  
Old 02-01-2008
Moving file to directory based on condition.

Can any one help me to correct following script.

I have 2 directories DropZone and ProcessZone. File pattern is *VEHDESCSUM*.
Finding the 'no of files' in DropZone directory using ls *VEHDESCSUM* |wc -l
If DropZone has more than one file or 0 files then exit 1
If DropZone has one file then move file from DropZone to ProcessZone.

I am trying with the following code. But I am getting errors.

#!/bin/sh
##########################################################

DROP_ZONE=/apps/dsadm/GMCCi2/DropZone
PROCESS_ZONE=/apps/dsadm/GMCCi2/ProcessZone

echo ${DROP_ZONE}
echo ${PROCESS_ZONE}

cd $DROP_ZONE

cnt = ls *VEHDESCSUM* |wc -l

echo ${cnt}
if [ cnt -gt 1 ]
then
exit 1
else
mv $DROP_ZONE/*VEHDESCSUM* $PROCESS_ZONE
exit 0
fi

##########################################################


thanks for all
# 2  
Old 02-01-2008
I think you have to use "$cnt" inside the bracket where you are checking for > 1
# 3  
Old 02-02-2008
I have done changes above script. But still getting errors: "argument expected" Could you please any one correct my script.
========================================

DROP_ZONE=/apps/dsadm/GMCCi2/DropZone
PROCESS_ZONE=/apps/dsadm/GMCCi2/ProcessZone

echo ${DROP_ZONE}
echo ${PROCESS_ZONE}

cd $DROP_ZONE

echo FILE_COUNT = ls *VEHDESCSUM* |wc -l

if [ $FILE_COUNT -ne 1 ]
then
exit 1
else
mv $DROP_ZONE/*VEHDESCSUM* $PROCESS_ZONE
exit 0
fi
=================================
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Perl - Moving file based upon filesize in folder

Hi I'm trying to look through a series of directories in A folder, lets just call it A: for example: A/1 A/2 A/3 Etc and I wish to move the files in the folder if they are bigger than a certain size into a structure like below: A/TooBig/1 A/TooSmall/1 A/TooBig/2 A/TooSmall/2... (1 Reply)
Discussion started by: PerlNewbRP
1 Replies

2. Shell Programming and Scripting

Moving files based on file name

Hi All, I have multiple files in the folder, I want to move those files into the other folder on based of name File names: Template_server1_01==> Template_server1_02==>To one directory /Server1 Template_server1_03==> Template_server2_01==> Template_server2_02==>To one... (9 Replies)
Discussion started by: sharsour
9 Replies

3. Shell Programming and Scripting

Moving files based on file creation

Hi, I have a directory having so many number of files. Now I want to move the files which are older than one month (lets say) from this directory to another directory (say BKP dir). Simply, if file is olderthan one month move it from source1 dir to BKP1 dir. My file names doesn't have... (7 Replies)
Discussion started by: karumudi7
7 Replies

4. Shell Programming and Scripting

Moving files from one directory to another based on 2 date variables

Hi All, I am currently coding for a requirement(LINUX OS) where I am supposed to move a file (Lets Call it Employee.txt) from Directory A to Directory B based on 2 date fields as below, Date_Current = 20120620 Date_Previous = 20120610 Source Directory : /iis_data/source Target... (11 Replies)
Discussion started by: dsfreddie
11 Replies

5. UNIX for Dummies Questions & Answers

moving files based on condition

hi i have to move files and send an email and attached the bad files to inform the developer about that. #!/bin/ksh BASE_DIR=/data/SrcFiles cd $BASE_DIR ## finding the files from work directory which are changed in 1 day find -type f -name "*.csv" –ctime 0 > /home/mydir/flist.txt ##... (14 Replies)
Discussion started by: awais290
14 Replies

6. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

7. Shell Programming and Scripting

How can I change file value based on condition

Hi, Gurus, I got a problem to resolve following issue: I have one file file1as following: start_dt=2010-01-01 12:00:02 start_dt=2011-01-01 09:00:02 start_dt=2009-01-01 11:00:02I have another file file2 as following: title1, 2010-01-03 10:00:02 title2, 2011-01-04 11:00:02 title3,... (5 Replies)
Discussion started by: ken002
5 Replies

8. Shell Programming and Scripting

Moving a file based on size

hello, I am creating a script that is going to scan the contents of a directory, and if it finds a certain DocumentName that is a certain size (The example, DocumentName and a size of 8777) If this file exists, it needs to be moved to a directory for later removal/processing..anyone have... (7 Replies)
Discussion started by: jeffs42885
7 Replies

9. Shell Programming and Scripting

Spliting file based on condition

Hi, I have a comma separated file with millions of records in it. I have a requirement to split the file based on the value in a one of the columns. Suppose i have a text file with columns like C1, C2,C3,C4 Column C4 can hold the values either 01 or 02 03 or 04. I nned to extract... (2 Replies)
Discussion started by: Raamc
2 Replies

10. Shell Programming and Scripting

Read file based on condition

Hi Friends, Can any one help with this: I have a huge file with the format as A SAM 4637 B DEPT1 4758 MILAN A SMITH 46585 B DEPT2 5385 HARRYIS B SAMUL 63547 GEORGE B DANIEL 899 BOISE A FRES 736 74638 I have to read this file and write only the records that starts with "B" only ... (5 Replies)
Discussion started by: sbasetty
5 Replies
Login or Register to Ask a Question