The list of Unix/Linux utilities available grows every day. Here’s a little list of cherry-picked utilities i’ve found myself using more and more lately…
Inotail:
Inotail uses the Linux kernel’s inotify API, which was implemented with v2.6.13 to monitor changes to files on the filesystem. This design is more efficient than our beloved tail, which relies on polling the monitored file for changes every second. Example: To monitor in real-time syslog entries, try:
inotail -f /var/log/messages |
The documentation for inotail, if you need it, can be found at http://distanz.ch/inotail/
Incron:
Incron is an event-scheduler similar to cron, except that it is based on file-system events as opposed to our beloved time-based cron daemons. It is also based on the inotify subsystem, which means it is only available on Linux as far as I know. Let’s set up a quick example to demonstrate the stuff you can do with incron. We’re going to install incron, and configure it to automatically create a thumbnail of any picture dropped in a specified directory using ImageMagick’s convert utility, on a stock Ubuntu Linux system:
# Package installation aptitude install incron imagemagick # Add your user account to the list of allowed incron users (replace xavier by your account) sudo sh -c "echo xavier >> /etc/incron.allow" # Create our directory structure mkdir -p /home/xavier/images/original mkdir /home/xavier/images/thumb # Edit the actual incron file incrontab --edit |
The editor will now fire up. Enter the following lines in the editor, and exit:
# Convert /home/xavier/images/original/test.png to /home/xavier/images/thumb/test.png /home/xavier/images/original/ IN_CLOSE_WRITE convert -thumbnail 320x320 $@/$# $@/../thumb/$# # When an original is deleted, automatically clean up the associated thumbnail /home/xavier/images/original/ IN_DELETE rm -rf $@/../thumb/$# |
We’re all done. Any new image dropped in /home/xavier/images/original/ will automatically be converted into a thumbnail of the same name in /home/xavier/images/thumb/. There are many things you can do with incron, so i suggest you check out the following links:
- Incron Documentation: http://inotify.aiken.cz/?section=incron&page=doc&lang=en
- Incron FAQ: http://inotify.aiken.cz/?section=incron&page=faq&lang=en
- inotify.h: http://www.kernel.org/pub/linux/kernel/people/rml/inotify/headers/inotify.h
ccze
ccze is simply a logfile syntax highlighter for various file-formats commonly found on unix systems, such as syslog, apache logs, dmesg, etc… You can have it syntax-highlight a file in your terminal by using the following syntax:
ccze < /var/log/messages |
Or you can pipe anything onto ccze to have it stream syntax-coloured output on your terminal. For example:
inotail -f /var/log/messages | ccze -A |
Additionally, ccze can also output syntax-coloured text in HTML. For example, the following command:
dmesg | grep -i cpu | ccze -m html |
Woud output the following document: ccze Output