[Nottingham] Putting remote ssh processes into the background

Michael Erskine msemtd at googlemail.com
Fri Mar 12 09:25:50 UTC 2010


Yup, screen FTW!

I also use screen to host long-running "poor man's services" too: my 5
min crontab has a script that looks for a screen session with a
particular name (ps auxww | grep or somesuch). If it doesn't exist
then it starts one off. In this way, I have a user-level
almost-always-on "service" (usually a POE TCP server of some kind)
without having to involve root to add items to init.d.

Regards,
Michael Erskine.
(script follows)
#!/bin/bash
# Make script crontab friendly:
# ==> Change to directory where this script lives.
cd $(dirname $0)

LOGFILE=servercheck.log
# want to redirect own stdout and stderr to logfile

exec >> $LOGFILE

echo `date`
echo "search for server process..."
echo `ps auxww | grep "SCREEN -dmS msgbridge" | grep -v grep`

if ! ps auxww | grep 'SCREEN -dmS msgbridge' | grep -v grep > /dev/null
then
    echo "*** WARNING *** seems not to be running -- starting server"
    # do something smart here - launch it in detached screen
    /usr/bin/screen -dmS msgbridge perl msgbridge.pl
else
    echo "seems to be running"
fi



More information about the Nottingham mailing list