coding conversion

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

suresh_dsx
Participant
Posts: 160
Joined: Tue May 02, 2006 7:49 am

coding conversion

Post by suresh_dsx »

this is the script is used for checking the files with an extension is *.csv


ext="*.csv"
if [ ! -f ${ext} ]
then
echo 'filename not found'
exit 1
fi

How can i convert this script in to the datastage...


If [ ! -f ${File_Name}] Then
Call DSLogFatal('Filename not found.' , c_routineName )
End

i tired like this....but i am getting an error.
0029 If [ ! -f PATH ] Then

'[' unexpected, Was expecting: Array Name, Variable name, New variable name,

please give some info or else i need to change the syntax..give me the exact conversion....
thx
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Re: coding conversion

Post by ArndW »

suresh_dsx wrote:If [ ! -f ${File_Name}] Then...
This is not DataStage BASIC syntax. The answer depends upon how you are getting a value for "File_Name" in the program.
suresh_dsx
Participant
Posts: 160
Joined: Tue May 02, 2006 7:49 am

Post by suresh_dsx »

File_name="*.csv"


can you please tell the actual syntax.just take as an example.how can we check the file format is correct or not.
thx
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

DataStage BASIC code is not shell script. The function "[ ! -f ${File_Name}]" will not work. You need to get the file list matching that pattern using a different method. How you do this depends upon where you are coding this.
Please look at the BASIC handbook and search for the function "DSExecute"
suresh_dsx
Participant
Posts: 160
Joined: Tue May 02, 2006 7:49 am

Post by suresh_dsx »

can you please give some information how i can give the syntax in the Datastage rountine....
thx
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

No, I won't give that syntax as it is described in the documentation I noted earlier. If you aren't will to read and give it a try (or even to search this forum for code snippets) then I'm not willing to invest time in doing it for you. If you'd actually tried something and it didn't work and posted your error I certainly would have.

Perhaps someone else here will do this for you.

You should also add where you are coding this - in a Routine? Job Control? DataStage Sequence? The answer depends on that. A sequence has builtin functionality that already does this check so you don't even have to write any BASIC
suresh_dsx
Participant
Posts: 160
Joined: Tue May 02, 2006 7:49 am

Post by suresh_dsx »

i am getting the same error..

"[ ! -f ${File_Name}]"

when i use this sytax in the basic. it is '!' will trat as Dimension of array.
Thats way i am asking the syntax


thx
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

But DataStage doesn't have this functionality of doing a wildcard lookup on a directory's files, you need to get that information from UNIX using DSExecute or a similar type of call. So there is no conversion, in the sense that you are looking for, possible.
suresh_dsx
Participant
Posts: 160
Joined: Tue May 02, 2006 7:49 am

Post by suresh_dsx »

i tried in this way.

$INCLUDE DSINCLUDE JOBCONTROL.H

Cmd = ('ksh ':Arg1:'/sh two.sh')
Call DSExecute("UNIX", Cmd, OsOutput, OsStatus)
Ans=OsOutput


OUTPUT

TEST #1
*******

Arg1 = /home/bells

Test completed.


Result = ksh: /home/noones/sh: cannot open



When i test the routine it is showing cannot open.

Acutually i have script in the UNIX(two.sh).
when i run the script it will give an output in the UNIX.

we can call the script file in datastage using the DSExecute.
we gave the ksh,Arg1(it is a path name),script name.
if it is unable to open means, we need to add any more information like
hostname,username,password...
how can we add all these information in the DSExecute(OsInput)
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

What happens if you issue your command "ksh /home/noones/sh two.sh" manually from a shell. Should be the same error you are seeing in DS? Perhaps your DataStage user doesn't have rx access to the executable "/home/noones/sh"?
suresh_dsx
Participant
Posts: 160
Joined: Tue May 02, 2006 7:49 am

Post by suresh_dsx »

i changed the permissions of the two.sh to full rights in the UNIX.
If i want to get the rights to access from DATASTAGE to UNIX
i checked in the Datasatge Administrator(did not see any options related to Access rights). How can i give the rights.how can i check in the datastage.
i checked that option in the unix(ksh/home/noones/sh two.sh)it is not working.
if i give normally like (sh two.sh) it is working fine...

any other possibilities.....
thx
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

suresh_dsx wrote:i...if i give normally like (sh two.sh) it is working fine...

But that isn't what you are calling from DataStage. What if you issue the exact same command?

Code: Select all

ksh /home/noones/sh two.sh
?
dsscholar
Premium Member
Premium Member
Posts: 195
Joined: Thu Oct 19, 2006 2:45 pm

Re: coding conversion

Post by dsscholar »

I am doing something similar in my code, I am checking if any file is at all present in a specific folder or not ...you can customize this code to fit in your requirement.

*Execute Unix commands to know if the folder is empty or not

ucom1 ='ls /abc/efg > /abc/FileList.txt'

CALL DSExecute('UNIX',ucom1,fil1,SYSRET)

ucom1 ='wc -l /abc/FileList.txt'

CALL DSExecute('UNIX',ucom1,fil1,SYSRET)

if fil1[1,9] = ' 0' then

*So folder is empty

Ans='N'
*************************************
You can modify the cmd to have

ucom1 ='ls /abc/efg *.csv > /abc/FileList.txt'

Hope this helps !
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

All this seems like overkill.
Create a job sequence. Include an Execute Command activity to execute your command.
Use the output and/or exit status from that command (available through activity variables) in a downstream Nested Condition activity or to provide a job parameter value in a Job activity.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
suresh_dsx
Participant
Posts: 160
Joined: Tue May 02, 2006 7:49 am

Post by suresh_dsx »

i tried in this way,

Cmd = ('ksh ':Arg1:'/two.sh')
Call DSExecute("UNIX", Cmd, OsOutput, OsStatus)
Ans=OsOutput

now i am getting the ouput.actually the problem is

USER1 USER2

Dastage(unix) username Datastage(unix) username.
user name: duser1 user name :d2user1

I created my script in the username:d2user1. I am calling that script in to another user
duser1.

As u said we wont have any permissions.as i understand the Datastage is a operating system dependent.
i moved that scipt in the same user name..now i am getting actual result...

the key point is the datastage is operating system dependent.By default we wont get permissions to access to the other users.
so we need to know that if one user try to access the other user data ,we need to get a permissions from administrator.



thanks for helping...
Post Reply