Page 1 of 1

Error executing UNIX shell script from after job routine

Posted: Wed Feb 04, 2009 5:21 am
by senthilmp
Hi,

Am having a script to execute after Job finishes, and i have specified it in the After Job Routine in (ExecSh) of the DS Job.

The script name is rejectfile.sh

And the script file contains

if
[[ `awk 'END{print NR}' /RejectFiles/Extractrejectfile.csv` -gt 1 ]]
then
uuencode /RejectFiles/Extractrejectfile.csv Extractrejectfile.csv|mailx -s Extract Errorfile xyz@hotmail.com
else
echo "File is empty"
fi

If i run this script in the UNIX, its executing correctly. But if i run using the DS job after job routine am getting the following error.

/RejectFiles/rejectfile.sh: [[: not found
File is empty

Can you pls help me out, how to achieve this.

Rgds,
Senthil MP

**Note: Subject changed to be more descriptive - Content Editor **

Posted: Wed Feb 04, 2009 5:54 am
by mk_ds09
If you are just checking the file is empty or not, why dont you just try to use -s flag..
I guess that could also help the remove the error which you are getting.. I suspect it is due to awk which you are using in the if loop.

Posted: Wed Feb 04, 2009 6:02 am
by Sainath.Srinivasan
I think he is looking for > 1 rows

Posted: Wed Feb 04, 2009 6:29 am
by mk_ds09
if
[[ `awk 'END{print NR}' /RejectFiles/Extractrejectfile.csv` -gt 1 ]]
then
uuencode /RejectFiles/Extractrejectfile.csv Extractrejectfile.csv|mailx -s Extract Errorfile xyz@hotmail.com
else
echo "File is empty"

fi


Else contains the 'file is empty'.that means it should be containing any records ! :D

Senthil,

Are you looking for empty file ?

In if loop are you checking for the records more than one or zero ?

Posted: Wed Feb 04, 2009 6:44 am
by Sainath.Srinivasan
Maybe it is written with header

Posted: Wed Feb 04, 2009 7:35 am
by chulett
I assume so.

Senthil, what is your user's default shell? I'll wager it is different from DataStage and your syntax is shell specific. That ".sh" file extension is meaningless, you need to set it in the script itself. For example:

Code: Select all

#! /usr/bin/sh
As the first line to force it to use the shell matching your file's extension. But double-check what your user's default is, the one that works, and set that one in the script.

Posted: Wed Feb 04, 2009 8:08 am
by senthilmp
Hi Chulet,

How to find the default shell mode, i have already used .sh scripts to execute in some jobs and it works well, only this is making problem.

Thanks
Senthil

Posted: Wed Feb 04, 2009 8:23 am
by chulett
Ask an admin or find your entry in the /etc/passwd file, the default shell is the last field.

Posted: Wed Feb 04, 2009 8:43 am
by Sainath.Srinivasan
Does the script run outside DS? i.e. from Unix

Re: Trouble in calling Unix script

Posted: Wed Feb 04, 2009 8:57 am
by chulett
senthilmp wrote:If i run this script in the UNIX, its executing correctly.