How to write a If loop..

Hi all..

I've written a script which reads all system backup information.

#!/bin/ksh

export ORACLE_SID=$1
export primaryhost=$2
export sid=`echo $ORACLE_SID| tr ['A-Z'] ['a-z']`
RESULTFILE=/oracle/PC9/backupstatus_prod.log

ssh -l ora${sid} ${primaryhost} "tail -1 /oracle/$ORACLE_SID/sapbackup/back$ORACLE_SID.log" | awk '{print echo "CURRENT :-- Start Date&Time: " $3,$4,echo "|| End Date&Time: "$5,$6,echo "|| RETURN CODE = "$7}' >> ${RESULTFILE}

exit 0

Now if would like to write a if statement for $7 output.

if the $7 value is 0 then it should write successfull.. and sometimes it can be value 6 hence it should write Inprogress...

How to we do this...?

Thanks in advance..

> cat sample
#!/bin/sh
Present_Date=`date`
LOAD_DAY=`date -d "$Present_Date" | cut -d " " -f 1`
echo $LOAD_DAY
if [ $LOAD_DAY = "Mon" ]; then
 echo "Monday"
 #statements;
else
 echo "Not Monday"
 #statements; 
fi

script execution

> sample
Wed
Not Monday
> 

I am not sure of your variable assignments in what you wrote. Will $7 always be numeric? Do you want to test as text? What are the possible result values and your next actions?
0 means "successful"
6 means "in progress"
other possibilities?

The reason for this question is that with many possibilities it is often better to use "case" rather than "if-then-else". "If-then-else" works well with only a couple of possibilities.

An if statement is not a loop.

Please put code inside

 tags.



#!/bin/ksh
 
export ORACLE_SID=$1
export primaryhost=$2
export sid=`echo $ORACLE_SID| tr ['A-Z'] ['a-z']`

[/quote]

[indent]
Why are you exporting these variables?

Since $7 is an awk variable, it has to be done as part of the awk script:

if ( $7 == 0 ) print "Successful"
else print "In progress"