1833793 Members
2462 Online
110063 Solutions
New Discussion

Need Help With ksh

 
Louise Harrell
New Member

Need Help With ksh

I am in the process of writing a korne shell script to accomplish the following:

Start SQLLDR if datafile exists
Sleep 25 mins
wakes up
check for FLAG file
If found, archive/move data, log, error and flag files to archive directory, then quit.
If flag file not found, then return to sleep for 15 mins, try again.

Keeping in mind that this is my first time using UNIX, I need to know if I'm at least on the right track. Any assistance/guidance would be greatly appreciated. Thanks.

This is what I have so far:

# ! /bin/ksh
export ORACLE_SID=XYZZ
export ORAENV_ASK=NO
. oraenv

IF (DATA=abc) THEN
sqlldr userid=xxx
control=ccc.ctl
bad=bbbb.bad
discard=dddd.dsc
log=llll.log
sleep 600
wake

ELIF (DATA != abc)THEN
sleep 1600
FI

5 REPLIES 5
Maureen Gunkel
Trusted Contributor

Re: Need Help With ksh

Louise,
It looks like you're on the right track, but you don't need the 'wake' command, it'll wake on it's own. Also, you can do 'else' rather than 'ELIF (DATA != abc)THEN'.
But you'll want to wrap the whole thing with a 'while' statement, otherwise it will just exit after sleeping. What I do is like this:
Kntnu=0
while [ $Kntnu -eq 0 ]
do
...all your stuff in here ...
done
Also, you'll want to put quotes around your two variable assignments, ie
export ORACLE_SID="XYZZ"
Hope this helps,
Mo
No matter where you go, there you are.
Jitendra_1
Trusted Contributor

Re: Need Help With ksh

I agree with Maureen. One more thing you should check is the syntax of if then fi. The test should be performed in [] instead of (). so your if statement should look like :
if [ $DATA = "abc" ]
then
something
elsif
something
fi
Learning is the Key!
Maureen Gunkel
Trusted Contributor

Re: Need Help With ksh

Good point, Hemant. I missed the () [] part!
Mo
No matter where you go, there you are.
Marc Veeneman
Advisor

Re: Need Help With ksh

DATA is a variable and needs to be preceded with a $. Beware, though, if it has not been assigned any value, the expression [ $DATA = "somestring" ] will generate an error. It is better to make the test:

if [ "$DATA" = "somestring" ]
then

fi

Enclosing $DATA in double quotes will allow a null value to be compared as a zero-length string.
marc seguin
Regular Advisor

Re: Need Help With ksh

... and use lowercase letters for keywords (if then else ...)