Small Script to check a background task is running

From SHellium Wiki
Jump to: navigation, search
Geographylogo.png In other languages: English | Afrikaans | Albanian | Arabic | Brazilian | Bulgarian | Catalan | Chinese | Croatian | Czech | Danish | Dutch | Esperanto | Estonian | Filipino | Finnish | Flemish | French | German | Greek | Hebrew | Hindi | Hungarian | Indonesian | Italian | Japanese | Latvian | Lithuanian | Macedonian | Malay | Malayalam | Norwegian (Bokmål) | Norwegian (Nynorsk) | Persian | Polish | Portuguese | Romanian | Russian | Serbian | Slovak | Slovenian | Spanish | Swedish | Turkish | Ukrainian | Urdu

Warning: this script is additional background process, so you will be locked if you already have 2 processes! Consider using crontab instead

This little script may help you to ensure PsyBNC keeps running on your shell. I came up with the idea of writing it when I figured PsyBNC has randomly stopped working on my shell. Hence I needed a mechanism to automatically start it again. To use the script simply copy the code below to a new file, e.g. bnccheck.sh and upload it to your shell or create it directly on your shell with an editor of your choice. Make sure to edit the paths to your desired logfile location and the place where PsyBNC is stored.

### megadilf's process checking script ###

#!/bin/sh


# defines location and name of desired logfile
logfile=/path_to_your_logfile/test.log

while [ 1 ]
do

# testing if psybnc is running, if not then start it and report time in logfile
if [ $(ps -u $USER | grep -c psybnc) = 0 ];

then

    echo "$(date) psybnc started" >> $logfile


# change path according to your psybnc!
    /path_to_your_psybnc/./psybnc
	

fi

# timeout for next test, 120 seconds = 2 minutes in this case. can be changed to any desired value.
sleep 120
done


Finally make the script executable
chmod +x bnccheck.sh


And run it
sh bnccheck.sh


It may be a good advise to run it in a screen session so it does not get killed once you disconnect from your shell.

screen -t bnccheck
sh bnccheck.sh

You can now disconnect from your shell and reconnect to your screen session at a later time by typing

screen -r

in your shell.

Personal tools
Namespaces

Variants
Actions
Navigation
Indexes
SHellium Sites
Toolbox