#!/bin/sh # == Teamspeak client autostarter script ===== # # Written by Ulf Larsson / SM0LCB # # ===================================== # # Add to crontab # "1-59/2 * * * * $HOME/check_teamSpeak_client.sh" # # ===================================== # Some settings # The PID process name for the server when doing a ps command CHECK_SERVER_PID_NAME="server_linux" # The PID process name for the client when doing a ps command CHECK_PID_NAME="TeamSpeak.bin" # The directory there you have Teamspeak server installed PID_PWD="TeamSpeak2RC2" # The script starting Teamspeak client PID_RUN="start_teamspeak_client.sh" # The log file LOGFILE="checkTeamSpeakClient.log" #Text information data TXT_SERVER_NOT_RUNNING="TeamSpeak sever is NOT running." TXT_CLIENT_IS_RUNNING="TeamSpeak client is running." TXT_CLIENT_START="TeamSpeak client not running - starting now..." TXT_CLIENT_START_OK="TeamSpeak client pid found. Startup successful." TXT_CLIENT_START_FAIL="TeamSpeak client still not started." TXT_CLIENT_KILL="No server but client running, kill client." # # Set current time TIME=`date '+%Y%m%d %H%M%S : '` # # Quietly check for ts process running ps -ef | grep -v grep | grep -q $CHECK_SERVER_PID_NAME if [[ $? -ne 0 ]] # Note double [[ ]] are important! then echo $TIME $TXT_SERVER_NOT_RUNNING >> $LOGFILE # Quietly check for ts process running ps -ef | grep -v grep | grep -q $CHECK_PID_NAME if [[ $? -eq 0 ]] # Note double [[ ]] are important! then echo $TIME $TXT_CLIENT_KILL >> $LOGFILE killall -9 CHECK_PID_NAME fi exit 0 # We can exit the script now fi # # Quietly check for ts process running ps -ef | grep -v grep | grep -q $CHECK_PID_NAME if [[ $? -eq 0 ]] # Note double [[ ]] are important! then echo $TIME $TXT_CLIENT_IS_RUNNING >> $LOGFILE exit 0 # We can exit the script now else # Process is *not* running echo $TIME $TXT_CLIENT_START >> $LOGFILE # Record current DIR pwd=$PWD # Move to the diretory for the Teamspeak client cd ~/$PID_PWD # Start the Teamspeak client ./$PID_RUN # Change back to our previous dir cd $pwd fi # # Check to see if TS has started up ps -ef | grep -v grep | grep -q $CHECK_PID_NAME if [[ $? -eq 0 ]] then echo $TIME $TXT_CLIENT_START_OK >> $LOGFILE else echo $TIME $TXT_CLIENT_START_FAIL >> $LOGFILE fi # == End of Teamspeak script ==========