1

I have a bash script that runs every 5 minutes via cron:

#!/bin/bash
echo "`users | wc -w`" users logged on @" `date`" >> /var/www/users.html

I need the output text to display in a html page in a single column. I have been using the following HTML code but don't know how to get the output from the script to display properly between the tags dynamically. The script will run and add the output after the HTML code:

<table>
<tr>
<td>2 users logged on @ Fri Jan 16 16:59:01 EST 2015</td>
</tr>
<tr>
<td>2 users logged on @ Fri Jan 16 16:59:01 EST 2015</td>
</td>
<tr>
<td>2 users logged on @ Fri Jan 16 16:59:01 EST 2015</td>
</tr>
</table>
2 users logged on @ Fri Jan 16 19:11:02 EST 2015
2 users logged on @ Fri Jan 16 19:12:01 EST 2015
2 users logged on @ Fri Jan 16 19:13:01 EST 2015
2 users logged on @ Fri Jan 16 19:14:01 EST 2015

Any help is appreciated thank you.

0

1 Answer 1

4

You can try this.

#!/bin/bash

VAR=$(echo "<td>`users | wc -w`" users logged on @" `date`</td>")
sed -i -e "$ i <tr>" -e "$ i $VAR" -e "$ i </tr>" /var/www/users.html

We are using sed to add the content instead of shell redirector.

Sign up to request clarification or add additional context in comments.

2 Comments

+1. I was going to suggest 1) appending each line to a separate text file, then 2) (re)creating the entire HTML document from the text file contents. I like your solution a lot better :)
Is there a way to sort so the higher number of logons are displayed at top of web page? Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.