Check for existence of a file

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
ag_ram
Premium Member
Premium Member
Posts: 524
Joined: Wed Feb 28, 2007 3:51 am

Check for existence of a file

Post 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 ?
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Sreedhar
Participant
Posts: 187
Joined: Mon Oct 30, 2006 12:16 am

Post 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.
Regards,
Shree
785-816-0728
ag_ram
Premium Member
Premium Member
Posts: 524
Joined: Wed Feb 28, 2007 3:51 am

Post 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 ..
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ag_ram
Premium Member
Premium Member
Posts: 524
Joined: Wed Feb 28, 2007 3:51 am

Post 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
Sreedhar
Participant
Posts: 187
Joined: Mon Oct 30, 2006 12:16 am

Post by Sreedhar »

Thanks for sharing your idea
Regards,
Shree
785-816-0728
Post Reply