Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created July 24, 2014 07:45
Show Gist options
  • Save timruffles/ab88b7cb1ca23498bc51 to your computer and use it in GitHub Desktop.
Save timruffles/ab88b7cb1ca23498bc51 to your computer and use it in GitHub Desktop.
tails a (runit) service by name, or tail all services on a machine
# tail a service by name
#
# svtail cad-server 50
#
# becomes
#
# tail -fn 50 /var/log/cad-server/current
#
svtail() {
local n=${2:-50}
local sv=${1}
if [[ -z $sv ]]; then
echo "Tailing all"
# find services with logs in standard place (our runit setup)
local services=$(__intersect <( printf "%s\n" `ls /etc/sv` ) <( printf "%s\n" `ls /var/log` ))
tail -fn $n `printf "/var/log/%s/current " $services`
fi
if [[ ! -e /etc/sv/$sv ]]; then
echo "Could not find service $sv in /etc/sv"
return 1
fi
tail -fn $n /var/log/$sv/current
}
__intersect() {
# -1, suppress only in 1, -2 supress only in 2 (leaving -3 - only in both)
comm -12 $1 $2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment