Page 1 of 1

check for file existence

Posted: Wed Jul 02, 2008 12:44 pm
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!

Posted: Wed Jul 02, 2008 12:55 pm
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

Posted: Wed Jul 02, 2008 1:23 pm
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.

Posted: Wed Jul 02, 2008 3:56 pm
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

Re: check for file existence

Posted: Wed Jul 02, 2008 10:20 pm
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.

Posted: Wed Jul 02, 2008 10:48 pm
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

Posted: Thu Jul 03, 2008 7:41 am
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

Posted: Thu Jul 03, 2008 4:13 pm
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.