0

There is just one log, which will have info on certain devices, that i am upgrading.

I use "tailf log" to monitor the log.

Now, say, I am upgrading 10 devices, the log will go on populating lines pertaining to ips of each 10 devices.

I am not concerned about all lines of the logs, but very few lines, like, image being copied to device, image deleted, image uploaded, device reload issued and so on..

what i am looking for is.. a script which will parse the ongoing logs, and grep for the txts that i am concerned about, like "image deleted", "device reload issued" and go on populating these grepped outputs to files named image_deletion_messages, device_reload_messages and so on..

and again, parse these files (image_deletion_messages, device_reload_messages) to determine ips from the logged messages and then save those ips to files named image_deleted_devices, reload_devices...........

And in turn, i'll monitor these files (image_deleted_devices, reload_devices) using tailf, instead of monitoring the entire log.

tailf log |grep "image deleted" >> image_deletion_messages

tailf image_deletion_messages |grep (a list of ips) >> image_deleted_devices

And the same way for other messages............

Above set of commands as part of a script..

and finally, i'll just monitor the below files alone..

tailf image_deleted_devices

I tried the above way and it doesn't seem to work.

1 Answer 1

0

Something like this...

E.g., pipegrep:

#!/bin/bash

tail -f "$2" | while read log
do
    echo $log | grep "$1"
done

This is obviously very basic. Enhance as needed.

1
  • Is this do the same ? tail -f "$2"|grep "$1" ?
    – X Tian
    Commented Feb 11, 2014 at 23:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .