LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-16-2016, 12:35 PM   #1
nenokmagic
LQ Newbie
 
Registered: Mar 2016
Posts: 7

Rep: Reputation: Disabled
Bash Shell, Who command to HTML table


Hi all.

So I am having a problem that I just can't figure out nor find any information on.

I am attempting to make a script that takes the who command and sorts it into a html table.

While attempting to do so, I keep getting all the information into each box. $row $col. Instead of separate boxes.

If I attempt to cut the who line using the cut command I only get some of the information instead of it all, as I attempted to cut them into pieces everything goes miss.

All in all, how do I fit the who command into an html table?
 
Old 04-16-2016, 01:13 PM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Hi!

Well, I solved this (nice exercise by the way!) using a small script (who_table.sh), that will get you this output:
Code:
./who_table.sh
cat who_table.html 
<table>
<tr>
<td>hmw</td>
<td>:0</td>
<td>2016-04-16</td>
<td>08:37</td>
<td>(:0)</td>
</tr>
<tr>
<td>hmw</td>
<td>pts/0</td>
<td>2016-04-16</td>
<td>13:02</td>
<td>(:0.0)</td>
</tr>
<tr>
<td>hmw</td>
<td>pts/1</td>
<td>2016-04-16</td>
<td>13:02</td>
<td>(:0.0)</td>
</tr>
<tr>
<td>hmw</td>
<td>pts/2</td>
<td>2016-04-16</td>
<td>19:36</td>
<td>(:0.0)</td>
</tr>
<tr>
<td>hmw</td>
<td>pts/3</td>
<td>2016-04-16</td>
<td>19:43</td>
<td>(:0.0)</td>
</tr>
<tr>
<td>hmw</td>
<td>pts/4</td>
<td>2016-04-16</td>
<td>19:45</td>
<td>(:0.0)</td>
</tr>
<tr>
</table>
It renders like a regular table when i open it in Firefox. If you show me what you have done this far, maybe I can help you out.
I used a for loop in combination with who, grep, lots of echo (pardon the pun), and if/else.

Best regards,
HMW

Edit: Spotted a minor bug; my script leaves a trailing <tr> tag at the end, but I can't be arsed to fix it right now, and - like I said - it renders just fine in Firefox despite it!

Last edited by HMW; 04-16-2016 at 01:15 PM. Reason: Found minor bug
 
Old 04-17-2016, 12:01 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
I get the same with just a while loop and 2 echoes (Psst: and no trailing tr .. hehe)
 
Old 04-17-2016, 01:33 AM   #4
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by grail View Post
I get the same with just a while loop and 2 echoes (Psst: and no trailing tr .. hehe)
PM or it didn't happen!
 
  


Reply

Tags
bash scripting



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
[SOLVED] Generate HTML report using shell script (BASH) rchincholkar Programming 3 07-21-2014 04:51 AM
[SOLVED] Run bash command taking input from HTML page - CGI script vickyk Programming 6 04-15-2013 11:36 PM
how we can create table in bash shell scripting ravidangaych Linux - General 2 06-20-2009 01:42 AM
shell script/command for converting columns/table onto a single line skuz_ball Programming 9 11-30-2007 03:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:45 PM.

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