Page 1 of 1
Execute Command Actvivty
Posted: Thu Oct 15, 2015 4:20 am
by Cutty Mark
Hi,
I have a requirement to check whether a specific file exists or not.
I used Execute Command Activity to call a script.
However I dono what mistake I have made, the script is not executing.
Getting below warning
Error: JobControl(@Execute_Command_0):Command /xyz/exist.sh did not finish OK, reply '1'
Script:
Code: Select all
#!/bin/sh
file="xyz/abc/mv.sh"
if [-f "$file"]
then
echo "$file exist"
else
echo "$file does not exist"
fi
In Execute command activity --> ExecCommand tab ---> Command field I have given the path location of the script as /xyz/exist.sh
Can any one help me with the issue???
Thanking you in advance
![Smile :)](./images/smilies/icon_smile.gif)
Posted: Thu Oct 15, 2015 6:45 am
by chulett
First off your "$file" is a relative path and I suspect you meant to use an absolute one - i.e. one that starts with a slash. Never mind that you technically should pass the path to the file as an argument and then set file=$1 and lastly pass back a status like 0 or a 1 rather than just the echo'd strings. IMHO. But anywho...
Did you test this outside of DataStage first? What happens when you execute it on the command line? What does echo $? show immediately afterwards?
Posted: Thu Oct 15, 2015 9:39 am
by MrBlack
Maybe there's a reason your scenario prevents this, but don't forget the usefulness of the "Wait For File" stage if you're able to use it.
Posted: Thu Oct 15, 2015 9:51 am
by chulett
True... the WFF stage with a wait time of zero simply does an existence check.
Posted: Thu Oct 15, 2015 1:38 pm
by qt_ky
Is your script executable?
Execute Command Actvivty
Posted: Thu Oct 15, 2015 11:25 pm
by Cutty Mark
Thanku for the response Chulett, MrBlack and qt_ky. I din run it in unix. However I changed the echo statement to return values i.e
Code: Select all
#!/bin/sh
file="xyz/abc/mv.sh"
if [-f "$file"]
then
return 0
else
return 1
fi
The script works fine.
However when I pass the script loaction in comman field, it is not working. So I passed the script path location in paramater field and passed 'ksh' in command field.
i.e parameter - /xyz/exist.sh
Command - ksh
Why is it so?
Which is the correct way to do?
Re: Execute Command Actvivty
Posted: Fri Oct 16, 2015 1:47 am
by naveenkumar.ssn
Hi,
There are two ways of executing the script in the unix one with the ./{ScriptName}.sh or you can give sh {ScriptName.sh}..However in Datastage it is better you follow executing using sh followed by name of the script to be executed .. in your case sh /xyz/exist.sh ... pass your file as a parameter to the script.
Let me know whether it works or not.
Happy to help !!!
Regards
Naveen
Re: Execute Command Actvivty
Posted: Fri Oct 16, 2015 3:26 am
by Cutty Mark
Thanku Naveen
I tried both ./{ScriptName}.sh and sh {ScriptName.sh} ways.
The script is not executing.
The only way working is ksh in command and passing file path as parameter.
![Smile :)](./images/smilies/icon_smile.gif)
Posted: Sun Oct 18, 2015 3:35 pm
by ray.wurlod
Your script IS being executed; it is reporting its exit status. The problem for the Execute Command activity is that your script may not be returning a zero exit status. Possibly it's returning the exit status of the test command. Force the script to have a zero exit status and all should be well.
Code: Select all
... if [-f "$file"]
then
echo "$file exist"
else
echo "$file does not exist"
fi
exit 0