Skip to content

A command line tool that call the given command for each input line matching the given regular expression pattern.

License

Notifications You must be signed in to change notification settings

nojhan/paternoster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

paternoster

A command line tool that call the given command for each input line matching the given regular expression pattern.

SYNOPSIS

paternoster [-h]

paternoster [-w] [-e] [-g] PATTERN COMMAND(S)

DESCRIPTION

paternoster read lines of text stream on the standard input and call COMMAND(S) for lines matching a given regular expression PATTERN.

If groups are specified in the regular expression pattern, only them are taken into account, else the whole matching pattern is considered.

You can specify several commands when using groups by separating them with spaces. If you indicate more commands than groups, the last ones will be silently ignored. If you ask for fewer commands, the last one will be duplicated across remaining groups.

OPTIONS

  • -h, --help: Show a help message and exit

  • -w, --nowait: Don't wait for the end of the current command before calling the next one. This will call commands as soon as they are met in the stream, If the stream is read fast, commands will most probably be ran quasi-simultaneously.

  • -e, --end: Run commands at the end of the input stream. Note that if the stream don't end (for example if you input from tail -f), nothing will be done until an interruption.

  • -g, --group: Capture groups as arguments for the CMD, instead of running CMD for each group. CMD must have as many formating placeholder as captured groups. For example, if you capture 3 groups, you must put 3 formating placeholders in CMD: paternoster --group "^(.*):(.*):(.*)$" "echo '>>> 1:%s 2:%s 3:%s <<<'" If placeholders count does not match the groups count, no substitution is made and the placeholders are left as is.

EXAMPLES

  • Make the speakers beep for every FIXME found in a source code: `cat paternoster.py | paternoster "FIXME" "beep"

  • Play a sound for each error or warning on a compiler output (you must have the corresponding sound files in you path): make 2>&1 | paternoster ".*(error|warning): .*$" "ogg123 %s.ogg"

  • Say out loud the error in a compiler output: make 2>&1 | paternoster ".*(error: .*)$" "espeak --punct=';{}()' '%s'"

  • Play a series of sounds corresponding to the sequence of errors and warning at the end of a compilation: make 2>&1 | paternoster --end ".*(error|warning): .*" "ogg123 %.ogg"

  • Notify the desktop every time a user logs in: tail -n 2 -f /var/log/auth.log | paternoster ".*session opened for user ([^\s]+)\s*" "notify-send '%s login'"

  • Notify the desktop every time a user logs in or out: tail -n 2 -f /var/log/auth.log | paternoster --group ".*session (opened|closed) for user ([^\s]+)\s*" "notify-send '%s %s'"

  • Play a sound corresponding to the status of the battery every time it is updated `tail -f battery-stats | paternoster --group "^[0-9]{7}([0-9]{3})" "play -n synth sin %s trim 0 0.05"

CREDITS

About

A command line tool that call the given command for each input line matching the given regular expression pattern.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages