Move files based on status


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move files based on status
# 1  
Old 11-13-2017
Move files based on status

Hi UNIX Experts,

Kindly help me in this requirement where i want to move files based on its status.
For Eg:
I have 3 dir's
--FileBox Dir
this directory will have all the files which i need to process (in informatica ETL Tool)

--Succeeded Dir
this directory will have files which successfully processed

--Failed Dir
files did not processed
and this is how it should work,
Code:
DIR1=tmp/FileBox
DIR2=tmp/Success
DIR3=tmp/Failed
for $file in $DIR1
pmcmd --this command calls my informatica ETL workflow and process the file
if return code for previous command is 0 
mv $file $dir2
else mv $file $dir3

i know this code is not even rough work but this is how my script would workSmilie
Also is there any way to show which file is in -progress something like if i am processing ABC.txt file then while running my scipt, display:
ABC.txt In - progress and same for other files also.

Please help me out on this.
TIA
# 2  
Old 11-13-2017
Most Unix and Linux commands return an exit status of zero for success and non-zero for failure. Now, the shell can either catch that exit status and run with it (I'll show you that below) or record it in the reserved shell variable $?. Consider:
Code:
true
status_val=$?
if [ status_val -eq 0 ]
then echo success
else echo fail
fi

By appending a command with && or || followed by another command you conditionally execute the second command depending on the status of the first:
Code:
false && echo this echo will never be executed
false || echo but this one will

You can combine them too:
Code:
[[ $(shuf -i 1-100 -n 1) -gt 50 ]] && "echo over 50" || echo "under 50"

I hope this helps you figure out how to write your program.

Andrew
# 3  
Old 11-13-2017
Please specify operating system and shell you are using.
This will help us help you.

Answering couple of questions will determine a complexity of the script required.

Do you intend to run your program scheduled (e.g. cron, at ) ?

How are files written in --FileBox Dir ?
Can a contention happen in case your script will process file which is just being copied ?

Do you need a control if the pmcmd program and your script is already processing file(s) ?

Hope that helps
Regards
Peasant.
# 4  
Old 11-14-2017
My UNIX version:
Code:
$ uname -a
Linux ucsdv181.symprod.com 2.6.32-696.10.3.el6.x86_64 #1 SMP Thu Sep 21 12:12:50 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux

-As of now i dont need to schedule my program i just need to run manually

-In FileBox dir files will be place from upstream so i want to group those files based on certain criteria and send each set of grouped files in different different file lists and process these groups parallely and after processing send files to either success or failed folder

-No i don't need control i just need to see which file is being processed
*I have unix script to group these files and create file lists
Let me know if require any other information.
# 5  
Old 11-14-2017
Read the Informatica Command Reference, it has few examples [section: Scripting pmcmd Commands]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move files with a certain suffix based on how many files are in another folder

Hello, First time poster. I am looking for a way to script or program the process of moving files from one folder to another, automatically, based on the count of files in the destination folder. I was thinking a shell script would work, but am open to the suggestions of the experts... (6 Replies)
Discussion started by: comtech
6 Replies

2. UNIX for Dummies Questions & Answers

Need script to move files based on month

Hi , I need a script which moves files based on month. Example : Apr 29 03:16 log4.txt Apr 29 03:16 log5.txt May 4 09:17 log1.txt May 4 09:17 log2.txt Move Apr files into Apr2015(Folder) Move May files into May2015(Folder). This is urgent requirement , if you can help me... (5 Replies)
Discussion started by: rockingvj
5 Replies

3. Solaris

Move files into different folders based on its month

Hi All, I want to move the files in to different folders based on the files month in the file timestamp. For example All the september files in the directory should moves into the folder "sep_bkp_files" , August files in to aug_bkp_files folder... Please help me to achive the above... (10 Replies)
Discussion started by: velava
10 Replies

4. Shell Programming and Scripting

Help in Logic - How to move files based on a condition

Hi All, I have 2 LINUX scripts (Lets say ScriptA & ScriptB) which copies files (lets say 'date_abc.txt , it goes to a while loop & checks for the files between 2 date varialbles) to directory X. (as Shown Below) These 2 scripts are called from 2 different Autosys schedules & runs at the... (3 Replies)
Discussion started by: dsfreddie
3 Replies

5. Shell Programming and Scripting

Move files to another directory based on name

Hi Folks, I have different type of file in my current directory. From my current directory i need to move the file which is start with csp_rules and if the file is having the string payg , then I need to move all this files to another directory /output/record. Please help me how to do this? ... (3 Replies)
Discussion started by: suresh01_apk
3 Replies

6. Shell Programming and Scripting

Need script to move files based on name

Hi folks, I'm new here and appreciate greatly any help. I have a bunch of files that need be moved and renamed. Fortunately, they are all in sequence... Present filename and path: /.catalog1/t76038_842-01 Move to: /.catalog1/76038-01 So, we need to drop the... (8 Replies)
Discussion started by: axslinger
8 Replies

7. UNIX for Dummies Questions & Answers

Move files based on year

Hi All, I have a directory which has crores of files since from 2003. I want to move ony the 2003 files to another directory. Please help (9 Replies)
Discussion started by: IHK
9 Replies

8. Shell Programming and Scripting

Move files based on year of creation

Hi All, I have a directory which has crores of files since from 2003 till now. I want to move only the 2003 files to another directory. Please help. Thanks (2 Replies)
Discussion started by: IHK
2 Replies

9. UNIX for Dummies Questions & Answers

Move files based on year

I have a directory which has crores of files since from 2003. I want to move only the 2003 files to another directory. Please help in doing this. Thanks (1 Reply)
Discussion started by: IHK
1 Replies

10. UNIX for Dummies Questions & Answers

how to move files into different folders based on filename

I need to move a bunch of files into folders that have the same name. I wanted to either do this with some filter command or some type of batch file that I could save that would already include all of the mv commands since I will have to do this process often. Whatever method you think is easier. ... (7 Replies)
Discussion started by: italia5
7 Replies
Login or Register to Ask a Question