LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-27-2017, 04:49 AM   #1
hruday
Member
 
Registered: Jun 2015
Posts: 88

Rep: Reputation: Disabled
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
 
Old 01-27-2017, 04:54 AM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917
What is your question?
 
Old 01-27-2017, 05:36 AM   #3
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydrurga View Post
What is your question?
I want output in mentioned html table format.
 
Old 01-27-2017, 05:39 AM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917Reputation: 2917
What does your output currently look like?
 
Old 01-27-2017, 05:49 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
So you'll need:

Code:
<table>
<tr><th>HOST</th><th>CPU-USAGE%</th><th>RAM-USAGE%</th></tr>
And then for each row of output you'll need (where VAL1 etc. is replaced with your actual result values)
Code:
<tr><td>VAL1</td><td>VAL2</td><td>VAL3</td></tr>
And at the end:
Code:
</table>
 
Old 01-27-2017, 05:49 AM   #6
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
5.2
Used: 3.80
4.3
Used: 4.71
 
Old 01-27-2017, 05:49 AM   #7
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hydrurga View Post
What does your output currently look like?
5.2
Used: 3.80
4.3
Used: 4.71
 
Old 01-27-2017, 05:51 AM   #8
hruday
Member
 
Registered: Jun 2015
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
So you'll need:

Code:
<table>
<tr><th>HOST</th><th>CPU-USAGE%</th><th>RAM-USAGE%</th></tr>
And then for each row of output you'll need (where VAL1 etc. is replaced with your actual result values)
Code:
<tr><td>VAL1</td><td>VAL2</td><td>VAL3</td></tr>
And at the end:
Code:
</table>
How do I insert this in between commands.?

As I have SSH command with parameters.
 
Old 01-27-2017, 05:57 AM   #9
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,185

Rep: Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377Reputation: 1377
Quote:
Originally Posted by hruday View Post
How do I insert this in between commands.?

As I have SSH command with parameters.
Run your commands one command at a time, with HTML tables the tags don't have to be on the same line.

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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
inserting command output in specific html table aristosv Linux - Software 1 04-06-2016 03:19 PM
Output not visible in html format? sysmicuser Linux - Newbie 9 05-07-2013 07:54 PM
process flex+bison output in gtk hash table and list store RudraB Programming 1 03-30-2013 11:55 PM
[SOLVED] How to store the output of command with pipes diwaker1984 Programming 3 01-20-2011 11:54 PM
i need rpm output in table format Uday123 Fedora 1 12-17-2005 05:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration