Computing.Net > Forums > Unix > IF-Then-Else syntax Help!!!!

IF-Then-Else syntax Help!!!!

Reply to Message Icon

Original Message
Name: patilsd
Date: January 25, 2005 at 14:02:20 Pacific
Subject: IF-Then-Else syntax Help!!!!
OS: Sun 5.8
CPU/Ram: 2gb
Comment:

I'm new to Unix scripting. I have created the follwing script, but it error out with following error:-

livps11:db2bws 16% archivelogbackup.ksh

archivelogbackup.ksh[45]: syntax error at line 67 : `fi' unexpected

Script is as follows:-

if [ $COUNT2 -eq 0 ] ; then <<<<<This is line 45

print $MSG3 >> $TEMP_FILE1

cat $TEMP_FILE1 >> $OUTPUT_FILE

elseif [ $COUNT1 != 0 ] then

print $MSG2 >> $TEMP_FILE2

find $BKPDIR \! -name $BKPDIR -prune -mtime -1 | xargs ls -ltr | tail -2 >> $TEMP_FILE2

cat $TEMP_FILE2 >> $OUTPUT_FILE

rmail -t "$TO_NAME" < $TEMP_FILE2

find $BKPDIR -prune -mtime 1 -exec mv {} /backup/temp \;

if [ $ARCHLOGBKPUSED -ge $SPACELIMIT ] then

print $MSG1 >> $TEMP_FILE3

cat $TEMP_FILE3 >> $OUTPUT_FILE

rmail -t "$TO_NAME" < $TEMP_FILE3

elseif

while [ $ARCHLOGBKPUSED -le $TOTALSPACE ]

do

mv $LOGARCHIVE/*.* $BKPDIR

done

fi <<<<<<<<<<This is line 67

fi



Report Offensive Message For Removal

Response Number 1
Name: vgersh99
Date: January 25, 2005 at 14:23:28 Pacific
Subject: IF-Then-Else syntax Help!!!!
Reply: (edit)

depending on your shell....

'man ksh' yields:

if list ; then list ; [ elif list ; then list ; ... ] [ else list
The list following if is executed and, if it
returns an exit status of 0, the list following
the first then is executed. Otherwise, the list
following elif is executed and, if its value is 0,
the list following the next then is executed.
Failing that, the else list is executed. If no
else list or then list is executed, then the if
command returns 0 exit status.


vlad
#include<disclaimer.h>


Report Offensive Follow Up For Removal

Response Number 2
Name: cdac1000
Date: January 26, 2005 at 05:43:44 Pacific
Subject: IF-Then-Else syntax Help!!!!
Reply: (edit)

Hi,

I think I see more problems than just one fi

I tried to indent your script, and this is what I think is missing.

if [ $COUNT2 -eq 0 ] ;
then <<<<<This is line 45
print $MSG3 >> $TEMP_FILE1
cat $TEMP_FILE1 >> $OUTPUT_FILE
elseif [ $COUNT1 != 0 ] <--- (missing ; here )
then
print $MSG2 >> $TEMP_FILE2
find $BKPDIR \! -name $BKPDIR -prune -mtime -1 \
| xargs ls -ltr | tail -2 >> $TEMP_FILE2

cat $TEMP_FILE2 >> $OUTPUT_FILE
rmail -t "$TO_NAME" < $TEMP_FILE2
find $BKPDIR -prune -mtime 1 -exec mv {} /backup/temp \;

<-- (missing fi here)
if [ $ARCHLOGBKPUSED -ge $SPACELIMIT ]
then
print $MSG1 >> $TEMP_FILE3
cat $TEMP_FILE3 >> $OUTPUT_FILE
rmail -t "$TO_NAME" < $TEMP_FILE3
elseif <-- ( what's the "condition" here?? where is "then")
while [ $ARCHLOGBKPUSED -le $TOTALSPACE ]
do
mv $LOGARCHIVE/*.* $BKPDIR
done
<--- ( Missing fi here)
fi <<<<<<<<<<This is line 67

fi

These things can be really common when ur writing the script for the first time.

Shoudn't the elseif be elif,

May be you just want to make conditions smaller.

just use

if [[ contition ]];
then
statemnt
else
statement
fi

(NOTICE speces and [[ .)

Might help solve your problem for now. Guess ur indenting script good. It really solve 50% of the problems.

regards

cdac.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: IF-Then-Else syntax Help!!!!

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software