Jump to content

rhcci

New Members
  • Posts

    5
  • Joined

  • Last visited

rhcci's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks kicken, That does capture the data, but it's just a blob of info., however I need to feed it into the formatted table that Barand suggested for it to be meaningful/readable. <?php exec('cat /cci/support/log/page.log | grep FETAL', $output); foreach ($output as $line){ echo split_row($line); } function split_row($str) { $date = substr($str,0,28); $str = substr($str,29); $arr = explode(' -- ', $str); $err = $arr[0]; $words = explode(' ', $arr[1]); $code = array_shift($words); $msg = join(' ', $words); return "<tr><td>$date</td><td>$code</td><td>$msg</td><td>$err</td></tr>\n"; } $lines = file('/usr/tmp/pagelog.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $logdata = ''; foreach ($lines as $line) { $logdata .= split_row($line); } ?> <html> <head> <title>Log sample</title> </head> <body> <table border='1' cellpadding='3'> <tr><th>Date</th><th>Code</th><th>Message</th><th>Error</th></tr> <?=$logdata?> </table> </body> </html>
  2. Thanks Barand! Can you tell why my file is not being written to? When the page loads I'm just getting a blank table and no pagelog.txt in the /usr/tmp <?php exec('cat /path/page.log | grep FETAL >> /usr/tmp/pagelog.txt'); function split_row($str) { $date = substr($str,0,28); $str = substr($str,29); $arr = explode(' -- ', $str); $err = $arr[0]; $words = explode(' ', $arr[1]); $code = array_shift($words); $msg = join(' ', $words); return "<tr><td>$date</td><td>$code</td><td>$msg</td><td>$err</td></tr>\n"; } $lines = file('/usr/tmp/pagelog.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $logdata = ''; foreach ($lines as $line) { $logdata .= split_row($line); } ?> <html> <head> <title>Log sample</title> </head> <body> <table border='1' cellpadding='3'> <tr><th>Date</th><th>Code</th><th>Message</th><th>Error</th></tr> <?=$logdata?> </table> </body> </html>
  3. Thanks Barand! That is exactly what I'm looking to produce. Each line will have the same format. A question I have though is if the file/exec() has 10 lines or 50 lines, based on how I tail it or grep it, how can I use a loop to display the multiple table rows? The number of rows would be fixed, ie, always 10 or always 50. it would not switch randomly as I will use a tail -f, tail, or grep -100, etc. to set it when I test the result and decide how many rows I need.
  4. Our DBA suggested sending the output of the exec() to a file and then processing the file. Then print the result. Is that along the lines you're talking about? He suggested using strings to process the file.
  5. Hi, I'm trying to build a 'simple' page to improve a process where I work. I'm wanting to do this. Read either the last line, the last 10 lines, or something I decide on from a log and display the output in table rows and columns. I've done this before with loops and db query's, but don't know how to approach it using php only as this is the first time I'm using it. So right now I have this in a table but it will only display one row. <tr><td colspan="5"> <?php //get auto page log echo exec('tail -5000 /path/page.log | grep FETAL') ; ?> </td></tr> This is the output Wed Oct 29 18:35:25 MDT 2014 1201 : WARNING -- speh1 WEBFETAL PROBLEM: fetal-sa-triage is NOT RUNNING-102 The second part of the problem is I'm wanting to find a way to 'extract' various data so it shows in the table colums like this The first column is just the row #, second is the date, third is a code name (above it's speh1), etc. <tr><td>1</td><td> Mon Oct 27 11:06:30 PDT 2014</td><td>mamc5</td><td>fetal-sa-ldr2 is NOT RUNNING-829</td><td> 1201: WARNING</td></tr> I have built a static page as a template, but next need to move to real data. Any suggestions appreciated.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.