coding conversion
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 160
- Joined: Tue May 02, 2006 7:49 am
coding conversion
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
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
Re: coding conversion
This is not DataStage BASIC syntax. The answer depends upon how you are getting a value for "File_Name" in the program.suresh_dsx wrote:If [ ! -f ${File_Name}] Then...
-
- Participant
- Posts: 160
- Joined: Tue May 02, 2006 7:49 am
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"
Please look at the BASIC handbook and search for the function "DSExecute"
-
- Participant
- Posts: 160
- Joined: Tue May 02, 2006 7:49 am
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
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
-
- Participant
- Posts: 160
- Joined: Tue May 02, 2006 7:49 am
-
- Participant
- Posts: 160
- Joined: Tue May 02, 2006 7:49 am
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)
$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)
-
- Participant
- Posts: 160
- Joined: Tue May 02, 2006 7:49 am
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
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
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
Re: coding conversion
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 !
*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 !
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 160
- Joined: Tue May 02, 2006 7:49 am
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...
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...