Modifying a DOS script to a AIX ksh script

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
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Modifying a DOS script to a AIX ksh script

Post by I_Server_Whale »

Hi All,

Just want to make sure that I'm aware that this question is not entirely related to DataStage and hoping that I won't get chastised for posting a scripting related question.

I have a requirement where I need to convert the existing DOS (.bat) scripts to korn shell scripts. I'm posting this question since I'm a novice to shell scripting and gurus here are very knowledgeable on the subject.

The below is an example of an existing DOS script:

Code: Select all

	ECHO OFF
REM This job runs daily and after CLAIMS and Written Premium.

del E:\Ardent\EDWDev\Logs\EDWD130AUDIT_Completed
del E:\Ardent\EDWDev\DataKC\EDWD130AUDIT_Completed

E:
CD E:\Ardent\DataStage\ServerEngine\bin

DSJOB -file e:\ardent\logon\prod\logon.ini HQS364 -run -jobstatus  -param RunType=RUN -param ParameterFile=e:\ardent\EDWProd\parameters\ParameterKC.ini -param ClearWorkArea=N -param OverRide=Y -warn 99999 EDW_PROD Batch::EDWD130AuditJob

ECHO OFF
SET ERRORLEVEL=0
IF NOT EXIST e:\Ardent\EDWDev\Logs\EDWD130AUDIT_Completed GOTO ENDIT

COPY  E:\Ardent\EDWDev\Logs\EDWD130AUDIT_Completed 	E:\Ardent\EDWDev\DataKC\EDWD130AUDIT_Completed

:ENDIT
IF NOT EXIST E:\Ardent\EDWDev\DataKC\EDWD130AUDIT_Completed echo !!!!!! DataStage Job FAILED !!!!!!
IF NOT EXIST E:\Ardent\EDWDev\DataKC\EDWD130AUDIT_Completed BLOWUP!
And with my rudimentary knowledge of scripting, I have converted the code to the following ksh script:

Code: Select all

#!/bin/ksh
set +v
# This job runs daily and after CLAIMS and Written Premium.

rm /Ardent/EDWDev/Logs/EDWD130AUDIT_Completed
rm /Ardent/EDWDev/DataKC/EDWD130AUDIT_Completed

DSHOME=/datastage/Ascential/DataStage/DSEngine
FILE1=/Ardent/EDWDev/Logs/EDWD130AUDIT_Completed
FILE2=/Ardent/EDWDev/DataKC/EDWD130AUDIT_Completed

$DSHOME/bin/dsjob -file /ardent/logon/dev/logon.ini HQS364 -run -jobstatus  -param RunType=RUN -
param ParameterFile=/ardent/EDWProd/parameters/ParameterKC.ini -param ClearWorkArea=N -param 
OverRide=Y -warn 99999 EDW_PROD Batch::EDWD130AuditJob

set +v
$?=0


if [ -e $FILE1 ]
then
    if [ -e $FILE2 ]
    then
        echo '!!!!!! DataStage Job Failed !!!!!!'
        echo 'IF NOT EXIST /Ardent/EDWDev/DataKC/EDWD130AUDIT_Completed BLOWUP!'
    fi
else
    cp  /Ardent/EDWDev/Logs/EDWD130AUDIT_Completed /Ardent/EDWDev/DataKC/EDWD130AUDIT_Completed
fi

exit 0
I would really appreciate if someone could evaluate the conversion and point out any flaws/mistakes.

Many Thanks in advance,
Whale.
Last edited by I_Server_Whale on Wed Feb 21, 2007 5:32 pm, edited 2 times in total.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

It looks reasonable to me. Instead of -e you might use -r to test for file existence.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Also, you could look here for some examples of ksh and dsjob control:

viewtopic.php?t=85578
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

kcbland wrote:It looks reasonable to me. Instead of -e you might use -r to test for file existence.
First of all, many thanks!! Ken.

I have learnt that the -r option checks whether the file is readable by the current process or not. And the -e option checks if the file exists or not. Pardon me, but I'm not able to see the obvious advantage of using -r option over the -e option. Please let me know if I'm missing something.

Your other post has a meticulously written, indented and commented ksh by you. Thanks for sharing and your inputs. :)

Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I_Server_Whale wrote:I have learnt that the -r option checks whether the file is readable by the current process or not. And the -e option checks if the file exists or not. Pardon me, but I'm not able to see the obvious advantage of using -r option over the -e option. Please let me know if I'm missing something.
It might as well not exist if you can't read it. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

It's a style point. In unix you need read permissions to "see" something, execute permissions to "enter" a subdirectory. Just because something exists doesn't mean you can do what you need to do.

The -r says you can see something, therefore it exists. A -e says it exists, but you can't necessarily see it. If you try to create it after a -e, but it exists under other permissions, your create will fail. To be absolutely accurate, you'd do a -e and then require a -r to know if you could create it. You may not care about all of this for your simple script, but we're talking style. You've probably learned as much as you want to know about ksh. :lol:
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

:lol: Thanks !!
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Its fine if you scripts is already working. Declaring variable wont have space in close to "=".
FILE2 = /Ardent/EDWDev/DataKC/EDWD130AUDIT_Completed
May be you might have just give for example, if so leave it.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Thank you kumar_s. I have made the correction.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
Post Reply