Nightly job error message when trying to execute script

Hello All,

I am getting the following error message when trying to execute the following script.

AWK=/usr/bin/awk
TR=/usr/bin/tr
SED=/usr/bin/sed
CAT=/usr/bin/cat
MAILFILE=/home//nightly_jobs.tmp
mailto=xxx@gmail.com
 Nigh_Status = `db2 "select TYPE from ETL.LOCK where STATUS <> 0 and PROCESSINST like 'NIGHTLY%'"`
 if [ $Nigh_Status -eq 0 ];then
  echo "Nightly Jobs - All Nightly jobs have been completed successfully for today" > $MAILFILE
 else 
  echo "Nightly Jobs - All Nightly jobs have been completed successfully for today except $Nigh_Status" > 
$MAILFILE
        fi
        cat $MAILFILE | mail -s $mailto
 
Error:
 
./nightly_jobs.sh
./nightly_jobs.sh: line 8: Nigh_Status: command not found
./nightly_jobs.sh: line 12: syntax error near unexpected token `newline'
./nightly_jobs.sh: line 12: `           echo "Nightly Jobs - All Nightly jobs have been completed successfully for today except $Nigh_Status" > '

Can you help me out in resolving this :

Thnaks.

Try following:
Correction 1 (Remove space before and after equal (=) sign)

 
Nigh_Status=`db2 "select TYPE from ETL.LOCK where STATUS <> 0 and PROCESSINST like 'NIGHTLY%'"`

Correction 2 (Looks like else block statement is in two lines, make it in one)

echo "Nightly Jobs - All Nightly jobs have been completed successfully for today except $Nigh_Status" > $MAILFILE

Also ensure this line

MAILFILE=/home//nightly_jobs.tmp                 # 2 slash followed by home
echo "Nightly Jobs - All Nightly jobs have been completed successfully for today except $Nigh_Status" > 
$MAILFILE

should be:

echo "Nightly Jobs - All Nightly jobs have been completed successfully for today except $Nigh_Status" >\
$MAILFILE

I tried the following, bust still not successful.

./nightly_jobs.sh
./nightly_jobs.sh: line 8: Nigh_Status: command not found
./nightly_jobs.sh: line 9: [: -eq: unary operator expected
Send options without primary recipient specified.
Usage: mail [-BDFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr]
             [-r from-addr] [-h hops] [-A account] [-R reply-addr] to-addr ...
       mail [-BDeHiInNRv~] [-T name] [-A account] -f [name]
       mail [-BDeinNRv~] [-A account] [-u user]

Please post the modified code

The modified code is :

AWK=/usr/bin/awk
TR=/usr/bin/tr
SED=/usr/bin/sed
CAT=/usr/bin/cat
MAILFILE=/home//nightly_jobs.tmp
mailto=xxx@gmail.com
 Nigh_Status = `db2 "select TYPE from ETL.LOCK where STATUS <> 0 and PROCESSINST like 'NIGHTLY%'"`
 if [ $Nigh_Status -eq 0 ];then
  echo "Nightly Jobs - All Nightly jobs have been completed successfully for        today"      > $MAILFILE
 else 
  echo "Nightly Jobs - All Nightly jobs have been completed successfully         for today except $Nigh_Status" > $MAILFILE
 fi
        cat $MAILFILE | mail -s $mailto

Still not getting the desired output.

Thanks

Look at my post #2. You didn't do correction1
Remove space before and after equal (=) sign

 
Nigh_Status=`db2 "select TYPE from ETL.LOCK where STATUS <> 0 and PROCESSINST like 'NIGHTLY%'"`

And following mail command should have "Subject"

 
cat $MAILFILE | mail -s "This is test email" $mailto

Still not getting the desired output after modifying the code:

The modified code is:

AWK=/usr/bin/awk
TR=/usr/bin/tr
SED=/usr/bin/sed
CAT=/usr/bin/cat
MAILFILE=/home//nightly_jobs.tmp
mailto=xxx@gmail.com
 Nigh_Status = `db2 "select TYPE from ETL.LOCK where STATUS <> 0 and PROCESSINST like 'NIGHTLY%'"`
 if [ $Nigh_Status -eq 0 ];then
  echo "Nightly Jobs - All Nightly jobs have been completed successfully for        today"      > $MAILFILE
 else 
  echo "Nightly Jobs - All Nightly jobs have been completed successfully         for today except $Nigh_Status" > $MAILFILE
 fi
        cat $MAILFILE | mail -s $mailto

---------- Post updated at 07:19 PM ---------- Previous update was at 07:17 PM ----------

There is a space before and after the = sign.but it is not showing here.

There shoudn't be any space before and after equal sign.
And also correct the mail command. Put subject.
Both of these corrections are mentioned in post #8.
Please post the error you get after correcting it. Also post the final code (if error comes) along with errors

from Nigh_Status = `db2
to Nigh_Status= 'db2.....

Get rid of the space between the equal sign and see if that works

As previously advised, remove the space characters either side of the equals sign, then try the script and post the results.

Nigh_Status=`db2 "select TYPE from ETL.LOCK where STATUS <> 0 and PROCESSINST like 'NIGHTLY%'"`

Afterthought:
We are all assuming that when you type the commands at the command prompt they work. i.e. You are scripting and existing working process.
Though I make no claims to being a "db2" expert I would be surprised if "db2" accepts SQL commands on the command line.
Should this guess prove to be correct, please post the command sequence from a relevant "db2" command line session which produces the required output.

Now, I am getting the following error message:

./nightly_jobs.sh: line 9: [: too many arguments

The code is :

AWK=/usr/bin/awk
TR=/usr/bin/tr
SED=/usr/bin/sed
CAT=/usr/bin/cat
MAILFILE=/home/nightly_jobs.tmp
mailto=xyz@gmail.com
Nigh_Status=`db2 "select TYPE from ETL.LOCK where STATUS <> 0 and PROCESSINST like 'NIGHTLY%'"`
if [ $Nigh_Status -eq 0 ];then
                echo "Nightly Jobs - All Nightly jobs have been completed successfully for today" > $MAILFILE
else
        echo "Nightly Jobs - All Nightly jobs have been completed successfully for today except $Nigh_Status" > $MAILFILE
fi
        cat $MAILFILE | mail -s "This is test email" $mailto

Any modifications please ?

---------- Post updated at 12:10 PM ---------- Previous update was at 11:06 AM ----------

The code is :

AWK=/usr/bin/awk
TR=/usr/bin/tr
SED=/usr/bin/sed
CAT=/usr/bin/cat
MAILFILE=/home/nightly_jobs.tmp
mailto=xyz@gmail.com
Nigh_Status=`db2 "select TYPE from ETL.LOCK where STATUS <> 0 and PROCESSINST like 'NIGHTLY%'"`
if [ $Nigh_Status="" ];then
echo "Nightly Jobs - All Nightly jobs have been completed successfully for today" > $MAILFILE
else
echo "Nightly Jobs - All Nightly jobs have been completed successfully for today except $Nigh_Status" > $MAILFILE
fi
cat $MAILFILE | mail -s "This is test email" $mailto