• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Another Ubuntu 6.10 Question: Printing the results of a program into an HTML file?

At the command line, I can run checkraid.

Checkraid is an alias to...

'/usr/local/bin/tw_cli /c0/u0 show'

Here is a sample result of checkraid:

Unit UnitType Status %Cmpl Port Stripe Size(GB) Blocks
-----------------------------------------------------------------------
u0 RAID-1 OK - - - 465.761 976771120
u0-0 DISK OK - p0 - 465.761 976771120
u0-1 DISK OK - p1 - 465.761 976771120



Question:

Is there any way I can set up a crontab that runs checkraid say once an hour and then "inserts" the results above into an HTML file?
 
echo `/usr/local/bin/tw_cli /c0/u0 show` >> /var/www/status.html

How about something like that?

To set up a crontab:

At the terminal, type this:
crontab -e
Add this to the end of the file:

0 * * * * echo `/usr/local/bin/tw_cli /c0/u0 show` >> /var/www/status.html

You could add styles and further formatting by adding a bit of HTML.

0 * * * * echo "<div style=\"status\">"`/usr/local/bin/tw_cli /c0/u0 show`"</div>" >> /var/www/status.html
 
The idea of the HTML formatting is to make it easier to read. Basically what you can do is use a stylesheet (CSS) so that you can make a nice little box.

EDIT: If you want a breakdown of each part of that "command", just say the word.
 
Right now it all apears as a single string:

Unit UnitType Status %Cmpl Port Stripe Size(GB) Blocks<br> -----------------------------------------------------------------------<b
>
u0 RAID-1 OK - - - 465.761 976771120<br>u0-0 DISK OK - p0 - 465.761 976771120<br>u0-1 DISK OK - p1 - 465.761 976771120

Edit: I have inserted breaks <br> where they need to be.
 
Oh that's fine if that's how you want it. It'll just look like a simple log.

I just like to go the extra mile. Here's what you want then:
0 * * * * echo `/usr/local/bin/tw_cli /c0/u0 show` >> /var/www/status.html
 
Heh. What I mean to say is that echo `/usr/local/bin/tw_cli /c0/u0 show` >> /var/www/status.html currently prints a single string and I DO want some formatting. I want the breaks where they should be so it looks like this:

Unit UnitType Status %Cmpl Port Stripe Size(GB) Blocks
-----------------------------------------------------------------------
u0 RAID-1 OK - - - 465.761 976771120
u0-0 DISK OK - p0 - 465.761 976771120
u0-1 DISK OK - p1 - 465.761 976771120

I am not sure where I insert the breaks. In the crontab?
 
And I see that if I keep running echo "<div style=\"status\">"`/usr/local/bin/tw_cli /c0/u0 show`"</div>" >> /var/www/status.html it simply keeps on adding the string to the same file. I wonder if there is a way for it to simply replace the existing text.
 
Okay, I have the following in crontab:

59,14,29,44 * * * * rm -rf /var/www/status.html

00,15,30,45 * * * * echo `/usr/local/bin/tw_cli /c0/u0 show` >> /var/www/status.html
 
The only way I can think of formatting it the way you want is to use php instead of HTML and str_replace lines to add the line breaks.
 
00,15,30,45 * * * * rm -rf /var/www/status.html && echo `/usr/local/bin/tw_cli /c0/u0 show` >> /var/www/status.html

A single > will replace the contents, there's no need to delete the file first.
 
Originally posted by: Nothinman
00,15,30,45 * * * * rm -rf /var/www/status.html && echo `/usr/local/bin/tw_cli /c0/u0 show` >> /var/www/status.html

A single > will replace the contents, there's no need to delete the file first.

I knew it would be something simple.
 
Originally posted by: Nothinman
00,15,30,45 * * * * rm -rf /var/www/status.html && echo `/usr/local/bin/tw_cli /c0/u0 show` >> /var/www/status.html

A single > will replace the contents, there's no need to delete the file first.

Thanks for that.

Do you have any idea on how to better format this thing besides using PHP?
 
If you just want to insert <br> where the newlines are you could do quickly by piping the output through sed before putting it in the file. Something like 'sed -e s/\n/<br>/' which I haven't tested. Personally if I really wanted to have it look pretty on a webpage, I'd probably write a small perl script to format the output how I wanted.
 
Sort of like, read string into array, and after character X, insert <br>, after character Y, insert <P>, etc.?

I have done nothing in perl before.
 
Sort of, but it would probably be simpler than that, one of perl's strongpoints is string manipulation. But unless you want to actually learn perl that's probably not a good solution for you.
 
Originally posted by: Nothinman
Sort of, but it would probably be simpler than that, one of perl's strongpoints is string manipulation. But unless you want to actually learn perl that's probably not a good solution for you.

😛

I am sure installing it alone would be a challenge.

YGPM
 
Back
Top