Execute Command Actvivty

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
Cutty Mark
Participant
Posts: 8
Joined: Wed Sep 30, 2015 2:39 am

Execute Command Actvivty

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

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

"You can never have too many knives" -- Logan Nine Fingers
MrBlack
Participant
Posts: 125
Joined: Wed Aug 08, 2012 8:57 am

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

Post by chulett »

True... the WFF stage with a wait time of zero simply does an existence check.
-craig

"You can never have too many knives" -- Logan Nine Fingers
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

Is your script executable?
Choose a job you love, and you will never have to work a day in your life. - Confucius
Cutty Mark
Participant
Posts: 8
Joined: Wed Sep 30, 2015 2:39 am

Execute Command Actvivty

Post 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?
Never Quit
naveenkumar.ssn
Participant
Posts: 36
Joined: Thu Dec 03, 2009 9:11 pm
Location: Malaysia

Re: Execute Command Actvivty

Post 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
Naveen Kumar
Datastage Consultant
Cutty Mark
Participant
Posts: 8
Joined: Wed Sep 30, 2015 2:39 am

Re: Execute Command Actvivty

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

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

Post 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
Last edited by ray.wurlod on Sun Oct 18, 2015 3:36 pm, edited 1 time in total.
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