#! /bin/bash # Set up a log viewer for fetchmail and procmail's logs # Absolute path to this script absProgPath() { LSOF=$(lsof -p $$ | grep -E "/"$(basename $1)"$") ABS_PATH=$(echo $LSOF | sed -r s/'^([^\/]+)\/'/'\/'/1 2>/dev/null) if [ $? -ne 0 ] then # We may be dealing with OSX, try another way ABS_PATH=$(echo $LSOF | sed -E s/'^([^\/]+)\/'/'\/'/1 2>/dev/null) fi echo $ABS_PATH } # Absolute path to directory containing the script absBinDir() { ABS_PATH=$(absProgPath "$1") echo $(dirname "$ABS_PATH") } CONF_FILE="$(absBinDir $0)/maillogs.screen" screen -S maillogs -c $CONF_FILE