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" > '
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 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
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.
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