Page 1 of 1

Check for existence of a file

Posted: Tue Mar 20, 2007 9:45 am
by ag_ram
Hi Folks

I have a requirement where certain extract and transformation need to happen if there is a file that is avaialable . quite simply if a look-up file is available use that to do some lookup and tranform else do another process .

As of now , i have split that into multiple jobs and i use shell script if-else conditions to call seperate sequencers , is there a better way to accomplish this ?

Posted: Tue Mar 20, 2007 9:59 am
by DSguru2B
Welcome Aboard :)
Do the same thing in a sequence job. Use wait for file activity to see if a file is present and then branch your execution accordingly.

Posted: Tue Mar 20, 2007 10:14 am
by Sreedhar
Ram,

Can you share, with us the logic, you have been using to find if the file exist or not with in the unix script. Hope that should help us when such a requirement come up.

Thanks in advance.

Posted: Tue Mar 20, 2007 10:17 am
by ag_ram
Iam kind of getting that , correct me if iam wrong here ,

if i use wait for file activity i can look for appearance of the file and timeout after a certain time .that way will be a way to distinguish if the file exists or not right ? ...

Is that possible to add logic for branching in that case ? or i have to have a nested condition to handle it ..

Posted: Tue Mar 20, 2007 10:19 am
by chulett
Sreedhar - just leverage the 'test' capabilities your shell. For example, for korn:

Code: Select all

if [[ -d ${DSHOME} && -w ${DSHOME}  && -x ${DSHOME} ]] ;then
Meaning: Is the $DSHOME 'file' a directory that is writable and executable by the current user?

Do a 'man' on your shell and there should be a section on Conditional Expressions. There should be... several.

Posted: Tue Mar 20, 2007 10:20 am
by chulett
ag_ram wrote:Iam kind of getting that , correct me if iam wrong here ,

if i use wait for file activity i can look for appearance of the file and timeout after a certain time .that way will be a way to distinguish if the file exists or not right ? ...

Is that possible to add logic for branching in that case ? or i have to have a nested condition to handle it ..
Use a wait time of 0 for a single 'file check'.

Two triggers - Ok and Otherwise. The former trigger defines your 'file found' path while the latter is your 'file not found' path.

Posted: Tue Mar 20, 2007 10:22 am
by ag_ram
Sreedhar wrote:Ram,

Can you share, with us the logic, you have been using to find if the file exist or not with in the unix script. Hope that should help us when such a requirement come up.

Thanks in advance.
Sure Sree

right now this is what iam doing .

if [ ! -f $lookupfile ]
then
echo "Lookup file [$lookupfile ] not found - Skipping Activity"
ProcP7.sh #sequencer to the process is called here
else
ProcP3.sh #sequencer to the lookup process is called here
fi

Posted: Tue Mar 20, 2007 10:28 am
by Sreedhar
Thanks for sharing your idea