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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

IF-Then-Else syntax Help!!!!

Reply to Message Icon

Name: patilsd
Date: January 25, 2005 at 14:02:20 Pacific
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




Sponsored Link
Ads by Google

Response Number 1
Name: vgersh99
Date: January 25, 2005 at 14:23:28 Pacific
Reply:

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>


0

Response Number 2
Name: cdac1000
Date: January 26, 2005 at 05:43:44 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Tranfer Unix Files awk question



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: IF-Then-Else syntax Help!!!!

Unix, Script, If then else www.computing.net/answers/unix/unix-script-if-then-else/6446.html

Bourne shell error if/then/else www.computing.net/answers/unix/bourne-shell-error-ifthenelse/4983.html

if then statement help www.computing.net/answers/unix/if-then-statement-help/7837.html