tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Feed facility/priority to logger(1) via stdin - desirable extension or bad idea?



On Thu, Oct 20, 2022 at 10:30:12PM +0100, Mr Roooster wrote:
> On Fri, 7 Oct 2022 at 14:19, Matthias Petermann <mp%petermann-it.de@localhost> wrote:
> >
> >
> > - Can what I have in mind already be solved (differently or more
> > elegantly) with existing tools from the base system?
> >
> It's not elegent, but depending on your shell you can abuse tee to do
> something like:
> 
> $ echo -e "alert|alert thing\ninfo|less important\n" |
>  tee >(grep "^info|" | cut -c6- | logger -puser.notice) |
>  grep "^alert|" | cut -c7- | logger -plocal0.notice

Uh... much easier than that, just using the standard shell's
builtin capabilities (and /usr/bin/logger):

$ printf "alert alert thing\ninfo less important\n" |
  (while read typeofmsg rest; do
	case $typeofmsg in
	alert)	prio="user.notice";;
	info)	prio="local0.notice";;
	esac
	logger -p $prio $rest
   done)

You can save the case...esac when you put the raw prio value as first
word of the line (whitespace separated from the rest of it):

$ printf "user.notice alert thing\nlocal0.notice less important\n" |
  (while read typeofmsg rest; do
   logger -p $typeofmsg $rest
  done)


(Btw: If you insist to use cut, use

...|cut -d\| -f2-|...

instead, it's more robust when you haven't to count the characters
on each reedit of the code.)

Regards
	-is


Home | Main Index | Thread Index | Old Index