Error executing UNIX shell script from after job routine

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
senthilmp
Participant
Posts: 85
Joined: Mon Sep 22, 2008 6:11 am

Error executing UNIX shell script from after job routine

Post 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 **
mk_ds09
Participant
Posts: 72
Joined: Sun Jan 25, 2009 4:50 pm
Location: Pune

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

What would you attempt to do if you knew you could not fail?

-----------------------------------
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

I think he is looking for > 1 rows
mk_ds09
Participant
Posts: 72
Joined: Sun Jan 25, 2009 4:50 pm
Location: Pune

Post 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 ?
-----------------------------------
Regards
MK

What would you attempt to do if you knew you could not fail?

-----------------------------------
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Maybe it is written with header
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

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

"You can never have too many knives" -- Logan Nine Fingers
senthilmp
Participant
Posts: 85
Joined: Mon Sep 22, 2008 6:11 am

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

Post by chulett »

Ask an admin or find your entry in the /etc/passwd file, the default shell is the last field.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Does the script run outside DS? i.e. from Unix
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: Trouble in calling Unix script

Post by chulett »

senthilmp wrote:If i run this script in the UNIX, its executing correctly.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply