1

I have to send status of 3 servers in HTML table format using shell script. Here is the output below:

---------------------------------------
|           Daily Status              |
---------------------------------------
|   Ad Status  |                      |
---------------------------------------
|   Servers    | Ser1  | Ser2 | Ser3  |
---------------------------------------
| Serv. Status |       |      |       |
---------------------------------------
| DB Server    |       |      |       |
---------------------------------------
|            Other Status             |
---------------------------------------
| Usage        |       |      |       |
---------------------------------------
|           Final Stats               |
---------------------------------------
| Total        |       |      |       |
---------------------------------------
| Success      |       |      |       |
---------------------------------------
| Fail         |       |      |       |
---------------------------------------
| Overall      |                      |
---------------------------------------

I tried as sample script to do this but getting output not like above table-

#!/bin/sh
 
spawn ssh [email protected]
interact

 ......
 ad_status=$(echo .....)
 if [[ $ad_status == "yes" ]]; then
    ad_status=$(echo "OK")
 elif [[ $ad_status != "yes" ]]; then
    ad_status=$(echo "NOK")
 fi
  .... <same for all variable which mention in below table format>
echo "
<html>
<body>
<table>
    <tr>
            <th>Daily Status</th>
            <tr><td>Ad Status</td><td colspan=3>$ad_status</td></tr>
            <tr><td>Servers</td><td>ser1</td><td>ser2</td><td>ser3</td></tr>
            <tr><td>Serv. Status</td><td>$server_status</td><td></td><td></td></tr>
            <tr><td>DB Server</td><td>$db_status</td><td></td><td></td></tr>
            .............
    </tr>
</table>
</body>
</html>" > abc.html

(uuencode abc.html abc.html) | cat abc.html | mail -s "$(echo -e "Status\nContent-Type: text/html")" [email protected]
exit 0

Issue is with print value which is in script in other server. Here 171.234.67.89 is IP address of other server2. I have to print variable ad_status which is in /path/script/test.sh of Server2 & Server3 as well. Main script is running in Server1 so i have already use password less authentication to connect to other server. In mail content value of other servers also print. Could you please help me on this.

4
  • I think you got the double quotes wrong. You don't need the outer quotes in my opinion. Also, I don't understand how you want the "OK" output to go to the mail. It just goes to stdout. Commented Mar 15, 2021 at 11:21
  • You've got some errors there. Paste your code into shellcheck.net. Commented Mar 15, 2021 at 14:12
  • 1
    This may not be flagged by shellcheck: if [[ $ad_status == "yes" ]]; then Commented Mar 15, 2021 at 14:14
  • @glennjackman, I could not getting any error. When i execute this script then getting value with OK/NOKin UNIX terminal but in mail i am getting content of value at_status (eg: Trying 171.123.34.67 to telnet ....) not as OK/NOK. I want in mail if "Yes" then "OK" if Not Yes then "NOK".
    – Md Wasi
    Commented Mar 15, 2021 at 14:17

2 Answers 2

1

I'm not sure exactly what you need, but it could be:

 ad_status=$(echo .....)
 if [[ $ad_status == "yes" ]]; then
    ad_status="OK"
 else
    ad_status="NOK"
 fi
2
  • Thanks a lot Glenn but now issue is with other server as well. I have to print variable ad_status which is in /path/script/test.sh of Server2 & Server3 as well. Main script is running in Server1 so i have already use password less authentication to connect to other server. In mail content value of other servers also print.
    – Md Wasi
    Commented Mar 16, 2021 at 7:14
  • This is quite different from your initial question. Please put some more thought into asking a new question Commented Mar 16, 2021 at 13:37
0

After connectivity done to other server then create variable like ad_status2 for 2nd server. call script then use variable/value of other script inside HTML tag.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .