check for file existence

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
sravanthi
Participant
Posts: 83
Joined: Fri Jun 02, 2006 5:37 am

check for file existence

Post by sravanthi »

Hi,

I have sequencer where i have to check for file existence then proceed further.I have used execute command activity and used test -e in command and passed parameter #filename#.But the job is showing a warning message and job is not detecting the file.

I have used return value =0 for file existence and 1 for file does not exist.

The warning is
Parameter 4 (' and return value is 1') does not start with a keyword

The log messsage :
seqtest..JobControl (@Execute_Command_440): Executed: test -e /test/stg/file.txt
Reply=1
Output from command ====>
SH: test: argument expected

The file is present on unix.
Thanks!
sravanthi
daignault
Premium Member
Premium Member
Posts: 165
Joined: Tue Mar 30, 2004 2:44 pm
Contact:

Post by daignault »

Have you checked your syntax? According to wikipedia: http://en.wikipedia.org/wiki/Test_(Unix)

1. To test whether a file is nonexistent or empty, type:

if test ! -s "$1"
then
echo $1 does not exist or is empty.
fi

If the file specified by the first positional parameter to the shell procedure, $1, does not exist, the test command displays an error message. If $1 exists and has a size greater than 0, the test command displays nothing.

Note: There must be a space between the -s function and the file name.

The quotation marks around $1 ensure that the test works properly even if the value of $1 is a null string. If the quotation marks are omitted and $1 is the empty string, the test command displays the error message
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

When you say you are returning "1" do you mean you have an "exit 1" in your script? If so, this behavior is expected. You see, if the script exits with a status other than 0 (0 for success) it signifies an error. That's the reason your sequence is throwing up a warning. Try changing your script to print something and then parse it in the sequence to find if the file existed.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
rameshrr3
Premium Member
Premium Member
Posts: 609
Joined: Mon May 10, 2004 3:32 am
Location: BRENTWOOD, TN

Post by rameshrr3 »

Isn't there a way in which you can use a WaitForFile Activity?
Otherwise you need to extract the Command.Output and parse it subsequently in the sequencer ( As noted)

HTH
John Smith
Charter Member
Charter Member
Posts: 193
Joined: Tue Sep 05, 2006 8:01 pm
Location: Australia

Re: check for file existence

Post by John Smith »

sravanthi wrote:Hi,

I have sequencer where i have to check for file existence then proceed further.I have used execute command activity and used test -e in command and passed parameter #filename#.But the job is showing a warning message and job is not detecting the file.

I have used return value =0 for file existence and 1 for file does not exist.

The warning is
Parameter 4 (' and return value is 1') does not start with a keyword

The log messsage :
seqtest..JobControl (@Execute_Command_440): Executed: test -e /test/stg/file.txt
Reply=1
Output from command ====>
SH: test: argument expected

The file is present on unix.
Thanks!
From your error message that "test" command did not run.It was expecting an argument. Try quoting the arguments.
Might want to put that test command in a script and put in error handling in the script and ensure you return a error code back to the calling program.
shaonli
Participant
Posts: 80
Joined: Tue Nov 28, 2006 6:52 am

Post by shaonli »

In my job I have the same file checking condition.So I have called a UNIX script from execute command stage with filename as parameter.
From script you need to return value.The script will look like below one
in_dir=$1
in_file=$2
if [ -s "$in_dir/$2" ]
then
exit 0
else
exit 1
fi
Now in trigger condition do the checking with this return value 0/1.

Thanks
Shaonli
sravanthi
Participant
Posts: 83
Joined: Fri Jun 02, 2006 5:37 am

Post by sravanthi »

Thank you for all your responses.

I have tried giving quotes for parameter but got same error.

I have used wait for file activity and it is working fine.

shaonli:I will try your script and see how it goes.

have good week end !

Thanks
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It's all too much. Use a simple test command, and create both OK and Failure triggers from the Execute Command activity.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply