Archive for the ‘Shell’ Category

ICQ Messages from Your Server

Tuesday, July 3rd, 2007

Often, I have long running jobs on various headless machines. Sometimes, I am eager to get the results, but get tired watching the console. Therefore, I wrote a small shell script that will send me an ICQ message once the job is done. To distinguish between several jobs, the message contains the original command and the last 10 lines of the result. This script takes another command as paremeter and also prints out the command’s stdout and stderr.


#!/bin/zsh
doReport() {
SINK="$HOME/.micq/scripting"
echo "msg NICK" > $SINK
echo "command: \"$@\":" > $SINK
tail > $SINK
echo "." > $SINK
}
$@ |& tee >(doReport $@)

It also requires a running instance of mICQ under the specified username. Due to the nice scripting interface of mICQ, automated sending of messages is made extremely easy. You have to replace NICK with the intended receiver’s nickname in mICQ.

dynamic window title for zsh session within screen

Thursday, April 6th, 2006

For quite some time I have now been using screen with a constantly visible window list. Up to now I had to manually set these window titles. Now I finally invested some time to get it working automatically with my favourite shell.

#.zshrc:
precmd () {
if [[ "$TERM" = "screen" ]]; then
local SHORTPWD=”`basename $PWD`”
echo -ne “\ek${SHORTPWD}/\e\\”
fi
}
preexec () {
if [[ "$TERM" = "screen" ]]; then
local CMD=”${1}”
if [[ ${#CMD} -ge 15 ]]; then
CMD=”${${(z)CMD}[1]} …”
fi
echo -ne “\ek${CMD}\e\\”
fi
}

#.screenrc
hardstatus alwayslastline
hardstatus string “%{= .W}%-Lw%{= C}%50>[%n* %t]%{-}%+Lw%= (%c)%< "