store command output in html table format
My shell script is as follows which logins into remote system through ssh and calculates cpu and ram usage.
Now I need to show the output in html and insert cpu and ram usage values in table like format for example ----------------------------------- HOST | CPU-USAGE% | RAM-USAGE% | ----------------------------------- a.b.c.d | 4.0 | 30.4 | ----------------------------------- 1.2.3.4 | 6.0 | 48.0 | ----------------------------------- #!/bin/bash USERNAME=root HOSTS="a.b.c.d 1.2.3.4" CPU_USAGE=ps -A -o pcpu | tail -n+2 | paste -sd+ | bc; RAM_USAGE=free -m | grep Mem | awk '{printf("Used :%.4f%\n",\$3/\$2*100)}' echo "<HTML>" >> cpunram.txt echo "<HEAD>" >> cpunram.txt echo " <TITLE>" >> cpunram.txt echo " SISTUDIO-HEALTH-STATUS" >> cpunram.txt echo " </TITLE>" >> cpunram.txt echo "</HEAD>" >> cpunram.txt echo "" >> cpunram.txt echo "<BODY>" >> cpunram.txt for ip in $HOSTS do if [ "$ip" == "a.b.c.d" ] ; then ssh -i /tmp/key1.pem ${USERNAME}@${ip} "${CPU_USAGE}" "${RAM_USAGE}" >> cpunram.txt elif [ "$ip" == "1.2.3.4" ] ; then ssh -i /tmp/key2.pem ${USERNAME}@${ip} "${CPU_USAGE}" "${RAM_USAGE}" >> cpunram.txt else echo "Wrong IP" fi done echo "</BODY>" >> cpunram.txt echo "</HTML>" >> cpunram.txt |
What is your question?
|
Quote:
|
What does your output currently look like?
|
So you'll need:
Code:
<table> Code:
<tr><td>VAL1</td><td>VAL2</td><td>VAL3</td></tr> Code:
</table> |
5.2
Used: 3.80 4.3 Used: 4.71 |
Quote:
Used: 3.80 4.3 Used: 4.71 |
Quote:
As I have SSH command with parameters. |
Quote:
Also you might want to name your output file .htm or .html rather than .txt You might also want to consider not using >> for the <HTML> tag as this will append to the file rather than create a new one. |
All times are GMT -5. The time now is 06:19 AM. |