Bash functions to grep log files

Hello,

inspired by the aliases tl and te in .bash_aliases I created 2 functions to grep logfiles:

function grl {
   egrep -i "$1" /var/log/${dir}/openhab.log
}
function gre {
   egrep -i "$1" /var/log/${dir}/events.log
}

I works like this:

openhabian@openhab3:~ $ gre pres_
2021-11-23 12:21:06.718 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Pres_Re_Home' changed from NULL to ON
2021-11-23 12:21:08.438 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Pres_Ro_Home' changed from NULL to OFF
2021-11-23 12:21:12.161 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'gpstracker:tracker:Pres_Re' changed from UNINED to INITIALIZING
...

As egrep is used it can also be used to grep for multiple strings:

openhabian@openhab3:~ $ gre 'RL_|HK_'
2021-11-23 12:21:04.567 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'RL_SZ_GF_l' changed from NULL to 0
2021-11-23 12:21:04.585 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'HK_SZ_ST' received command 17
...

Have a nice day
Reinhold

1 Like

Thanks for posting! I’ve moved this post to the Tutorials and Solutions category. Development is more for discussions on the development of openHAB.

1 Like