execute command to check for a existance of a file on unix

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
Chandrathdsx
Participant
Posts: 59
Joined: Sat Jul 05, 2008 11:32 am

execute command to check for a existance of a file on unix

Post by Chandrathdsx »

I am checking for a existance of a file (on unix) using Execute command stage (script: ls #Filename#) and in triggers: 1. if expression type 'OK' branching to file exists link, 2. if expression type 'otherwise' branching to file does not exists and I have other processes from these branches.
It is running fine but giving following warning:
JobControl (@Execute_Command_0): Command ls did not finish OK, reply = '2'

I tried to use CONVERT(@FM, "",Execute_Command_0.$returnvalue) > 1 for file does not exist link but no luck.

Could you please let me know how to get rid of this warning (other than suppressing it) or is there a better way to check for existance of a file?

Thank you!
Chen That
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Wait for file activity maybe....
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I would use one of the the test operators, perhaps "test -e" or with -f or -s depending on how tightly you need to test it.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Chandrathdsx
Participant
Posts: 59
Joined: Sat Jul 05, 2008 11:32 am

Post by Chandrathdsx »

chulett wrote:I would use one of the the test operators, perhaps "test -e" or with -f or -s depending on how tightly you need to test it. ...
Craig,
Thank you for the details. I tried with test -e but, still getting the warning when file does not exist:
JobControl (@Execute_Command_0): Command test -e did not finish OK, reply = '1'
But, the branching logic is working same as 'ls #filename#' when file doesn't exist.
[only difference I noticed is for test -e getting return value of 0 if file exists and return value of 1 if file does not exist. and it is not giving any command output(which I do not need). In case of 'ls #filename#' I am getting return value =0 or 2 and with command output as 'fileexsts' 'file not found'.

DSguru2B,
I am reluctant to use 'wait for file' as actually I do not want to wait, I check for existance of a file in a loop and branch based on condition.

Thank you all!
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That's because you are using the 'Automatically handle activities that fail option' but your triggers should override that if you are using the right pair of triggers out of the stage: 'Conditional (OK)' and 'Otherwise'. Are you saying that you are and it still logs the warning? :?

ps. A Wait For File stage with a wait time of zero seconds will do a simple file existence check.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Chandrathdsx
Participant
Posts: 59
Joined: Sat Jul 05, 2008 11:32 am

Post by Chandrathdsx »

chulett wrote:That's because you are using the 'Automatically handle activities that fail option' but your triggers should override that if you are using the right pair of triggers out of the stage: 'Conditional (OK)' and 'Otherwise'. Are you saying that you are and it still logs the warning? :?

ps. A Wait For File stage with a wait time of zero seconds will do a simple file existence check.
Craig,
Yes, I am using ''Automatically handle activities that fail option' as I want to fail the job for any failure [this sequence has lot of other steps/stages/jobs]. But I am using the right pair, 'Conditional (OK)' and 'Otherwise'. when file not found the othewise issuing a warning.

I tried with 'Wait of File Activity' with zero seconds, using right pair for trigger branches. but still it gives a warning for otherwise (when file doesn't exist): Routine DSWaitForFile did not finish OK, return code = '-14'
Any suggestions? Should I live with warning when file does not exist, if no other options?
Thank you for all the help!
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

See if this helps.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Chandrathdsx wrote:Yes, I am using ''Automatically handle activities that fail option' as I want to fail the job for any failure [this sequence has lot of other steps/stages/jobs].
That's fine and exactly what it is meant to do. I should have been more specific and thought about this for a moment longer - your triggers are working fine otherwise your message would be about an unhandled error being encountered. That specific trigger pair lets the code generater know that you are handling any "error" and that it doesn't have to include code to do that. If you are feeling adventurous, you can change the design and see the difference in the code it generates in the Job Control tab. :wink:

Uncheck the companion compilation option to Log warnings after activities that finish with status other than OK, you don't really need that to achieve your primary goal and it is what is actually causing your issue.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Chandrathdsx
Participant
Posts: 59
Joined: Sat Jul 05, 2008 11:32 am

Post by Chandrathdsx »

Thank you.
I unchecked 'Log warnings after activities that finish with status other than OK' to get rid of warning.

Thanks again
Post Reply