The sys admin's daily grind: Snoopy
Guide Dog
Sometimes sys admin Charly needs to know when exactly he did something ingenious on one of his servers. Finding an infallible memory aid is difficult, you might think. "Peanuts!" says Charly.
At work, I'm sometimes plagued by annoying gaps in my memory: What exactly was the name of that neat tool that I used to flash the LEDs on a specific network adapter to help me find the NIC in the rack? Or: How exactly did I delete all files that were more than a week old in a directory? The answer to all of these questions is in the Bash history, but Murphy's Law dictates that the history is always a little bit too short. And, in my case, there's another degree of uncertainty: Which server did I do this on?
Snoopy potentially offers a solution. The small library with the dog's name, wraps around execve()
and always wakes up when the computer runs a command. Many distributions have Snoopy in the pen, but if not, GitHub [1] will help you out. To enable Snoopy at boot time, you need an entry in /etc/ld.so.preload
. I added the following line: /<path>/snoopy.so
. The path is typically lib
. If you are building Snoopy yourself, the library is likely to be found in /usr/local/lib/
or something similar.
Building Snoopy yourself does offer some benefits. For example, you can edit the snoopy.h
header file in the source up front. If you enter
#define ROOT_ONLY 1
Snoopy only logs commands that run with root privileges, but if you install the tool from the distribution repositories, this option is not set, and it logs any old command no matter who ran it.
Unless configured to do otherwise, Snoopy writes to /var/log/auth.log
. Figure 1 shows the log for some simple commands. The structure always stays the same; each entry starts with the user ID, followed by the session ID and the TTY you use. This is then followed by the working directory, which is important because Snoopy does not log commands like cd /etc
. Navigating the system is not the same for this dog as executing a file.
This information is followed by the full path to the executed file and, finally, the expanded command (e.g., aliases can cause an expansion). Many distributions run ls --color=auto
, so, in this case, if you only type ls
, Snoopy reveals all.
Collection Point
Now you just need to consolidate the logs centrally. I configured one server to accept the log messages from other machines. If the server runs rsyslog, you can just pass in the -r
parameter at boot time to switch rsyslog to receive mode. Next, you can tell your other servers also to send entries in /var/log/auth.log
to the newly configured syslog server. To do this, you just need to add one line to the syslog configuration:
auth,authpriv.* @<192.168.2.80>
The auth log tends not to grow drastically, which means you can rotate on a weekly or even monthly basis. Snoopy fills a substantial log of my heroic deeds of administration day after day – including typos and similar peanuts.
Charly Kühnast
Charly Kühnast is a Unix operating system administrator at the Data Center in Moers, Germany. His tasks include firewall and DMZ security and availability. He divides his leisure time into hot, wet, and eastern sectors, where he enjoys cooking, freshwater aquariums, and learning Japanese, respectively.
Infos
- Snoopy: https://github.com/a2o/snoopy
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.