Shell script for generating HTML out put

Posted by user1638016 on Stack Overflow See other posts from Stack Overflow or by user1638016
Published on 2012-09-01T09:15:06Z Indexed on 2012/09/01 9:38 UTC
Read the original article Hit count: 157

Filed under:

The following script is generating the desired out put but not redirecting the result to /home/myuser/slavedelay.html

#!/bin/bash

host=<ip>
echo $host
user=usr1
password=mypass
threshold=300
statusok=OK
statuscritical=CRITICAL

for i in ert7 ert9
do
echo "<html>" > /home/myuser/slavedelay.html

if [ "$i" == "ert7" ]; then
        slvdelay=`mysql  -u$user -p$password -h<ip> -S /backup/mysql/mysql.sock -e 'show slave status\G' | grep Seconds_Behind_Master | sed -e 's/ *Seconds_Behind_Master: //'`
         if [ $slvdelay -ge $threshold ]; then
                echo "<tr><td>$i</td><td>CRITICAL</td>"  >> /home/myuser/slavedelay.html
                echo "<tr><td>$i</td><td>CRITICAL</td>" 
        else
                echo "<tr><td>$i</td><td>OK</td>"  >> /home/myuser/slavedelay.html
                echo "<tr><td>$i</td><td>OK</td>"
         fi
fi
done
echo "</html>" >> /home/myuser/slavedelay.html

If I cat the output file /home/myuser/slavedelay.html it gives.

<html>
</html>

Execution result :

sh slave_delay.sh 
<tr><td>sdb7</td><td>OK</td>

© Stack Overflow or respective owner

Related posts about shell