lundi 22 février 2016

grep, tail & awk

The Problem

I need to monitor a log file and take action when a certain string is caught. Then I need to parse a piece of the line and take an action. The log file rolls over when it gets to a certain size.

Here's a sample of the string I'm tracking:

[02/22/2016 07:59:07] <File Updated, size 5277077, NoChange 1 min. Filename(/home/autosys_prd/jobname)>

When I see that in the log file, i need to parse out the jobname and issue this command: sendevent -E FORCE_STARTJOB -J jobname

Some solutions I've discovered so far


I've solved the rollover with tail -follow=name (I honestly had no idea this existed until today. Dang!)

But my issue comes with the grep/parse/execute. The string can differ based on the filesize being different, so I can't cut on column.

If I do tail -follow=name logfile | grep autosys_prd and then try to pipe that into another command it just hangs and doesn't do anything.

So I searched around on the web and then came up with this command:

tail --follow=name logfile | awk '/autosys_prd/ {print substr($0, 0, 56);fflush("")}'

which sort of works, but again - I can't really use substr because the file size changes.

So, now I'm at this command:

tail --follow=name logfile | awk '/autosys_prd/ {print ($10);fflush("")}'

This gets me much closer - the output of that is

Filename(/home/autosys_prd/jobname)>

But then what? Redirect that to a script? Some combination of xargs/awk? Give up?

Appreciate any advice you guru's can give me...

Here's some bribe money.....

Attached Images
File Type: jpg bribe.jpg (7.5 KB)


via International Skeptics Forum http://ift.tt/1Q5XM9R

Aucun commentaire:

Enregistrer un commentaire