I am using a MacBooPro10,1 Debian stable (default install with rsyslogd) system for which the trackpad eventually fails (pointer stop working) from time to time as can be seen :

$ dmesg
[1910159.662967] bcm5974: bad trackpad package, length: 8

The solution is trivial:

$ sudo rmmod bcm5974 && sudo modprobe bcm5974

But I'd rather have it being done automatically.

How can I parse dmesg output and trigger a command (sudo power) ?

  • Are you using rsyslogd for logging? – meuh May 15 at 13:17
  • @meuh clarified – malat May 15 at 14:42

You can ask rsyslogd to run a program when it matches the line. Create a file such as /etc/rsyslog.d/my.conf with a line like

:msg, contains, "bad trackpad package" ^/bin/mytrackpadreset

and this will run the script /bin/mytrackpadreset when the message is seen, passing the whole message as a single string argument. As the daemon runs as root, you can simply put the required rmmod bcm5974 && modprobe bcm5974 command in the script, though you might need to set a suitable PATH first.

I think in the past rsyslogd would wait for the script to end before continuing, but this no longer seems to be the case. If you expect to see the message many times in a burst, you may need some extra work in the script to cope with being run several times in parallel.

This legacy format (^program) is superceded by the omprog module which is more useful for programs you want to start once, and run continuously, passing messages to it on stdin.


With a little bit of grep-ing, you'll find the same information that dmesg output in /var/log/messages.

There remains the question of watching this file without wasting resources (and without a "one-minute cron", which is pretty inelegant)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.