Page 1 of 1

Modifying a DOS script to a AIX ksh script

Posted: Wed Feb 21, 2007 2:48 pm
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.

Posted: Wed Feb 21, 2007 3:13 pm
by kcbland
It looks reasonable to me. Instead of -e you might use -r to test for file existence.

Posted: Wed Feb 21, 2007 3:14 pm
by kcbland
Also, you could look here for some examples of ksh and dsjob control:

viewtopic.php?t=85578

Posted: Wed Feb 21, 2007 3:44 pm
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.

Posted: Wed Feb 21, 2007 3:54 pm
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:

Posted: Wed Feb 21, 2007 4:11 pm
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:

Posted: Wed Feb 21, 2007 4:30 pm
by I_Server_Whale
:lol: Thanks !!

Posted: Wed Feb 21, 2007 4:55 pm
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.

Posted: Wed Feb 21, 2007 5:33 pm
by I_Server_Whale
Thank you kumar_s. I have made the correction.