#!/bin/bash # Requires inofity-tools. # Get filename to watch. if [[ -z "$1" ]] then cat << EOM Usage: $(basename $0) [-c ] [args to 'notify-send' ...] EOM exit 1 fi fname="$1" shift # Lines of context? context=10 if [[ "$1" == "-c" ]] then context="$2" shift shift fi # Make sure it exists. if [[ ! -f "$fname" ]] then touch "$fname" || exit 1 fi # Enter the watch loop. while inotifywait -q -q -e close_write "$fname" do notify-send "$@" "$(tail -n "$context" "$fname" | tac)" done notify-send "$@" "Error: Can no longer watch \`$fname'!"