0

This might be the wrong place to ask this as it's Bash scripting but I'm on an Ubuntu 15.10 server and I figured there's some knowledgeable people here.

My TeamSpeak and sometimes TSDNS crash, so I created a script to help me with that. I'm not to good with Bash and it's been a while, but this is what I've got:

#!/bin/bash
date=date
echo -en "\e[32mRunning \e[33mtscrashcheckscript"
sleep 1
irunloops
irunloops() {
  #go to ineedloops to recheck for ts running
  sleep 1
  ineedloops
}

ineedloops() {
  if pgrep -x "ts3server" | pgrep -x "tsdnsserver" > /dev/null
  then
    #Go to irunloops to restart (so you loop it)
    sleep 14
    irunloops
  else
    #have it output to log in format and restart program
    cd /home/teamspeak1/teamspeak3-server_linux_amd64/
    ./ts3server_startscript.sh restart
    cd /home/teamspeak1/teamspeak3-server_linux_amd64/tsdns
    ./tsdnsserver
    echo "##############################################################################" >> /home/teamspeak1/tscrashlog.txt
    echo "| ${date}">> /home/teamspeak1/tscrashlog.txt
    echo "| Teamspeak/TSDNS is not Running restarting!" >> /home/teamspeak1/tscrashlog.txt
    echo "| Closed and Restarted TSDNS. Restarted TS">> /home/teamspeak1/tscrashlog.txt
    echo "##############################################################################" >> /home/teamspeak1/tscrashlog.txt
  fi

I run this script and it does the beginning message that it starts running but then in ps aux it doesn't show up and doesn't run.

  1. Is there a better way to loop? I never really learned while loops so I figured to just stick away from it
  2. What've I done wrong to not make the ineedloops() not run?

If you need any more info just ask. Sorry if my Bash is messy or bad etc.

  • 15.10 reached EOL in July. You need to switch to a supported release. – wjandrea Jan 13 '17 at 0:03
  • Perhaps start by taking a step back and telling us exactly what the script is supposed to be doing. I doubt pgrep -x "ts3server" | pgrep -x "tsdnsserver" does what you intend (are you trying to perform a logical OR?) – steeldriver Jan 13 '17 at 0:08
  • it's a bit unclear – user595510 Jan 13 '17 at 0:23
  • ... I can't help feeling you should be using the appropriate respawn capabilities of your system's init system (upstart/systemd), rather than trying to script this manually – steeldriver Jan 13 '17 at 0:36
  • the whole (intended) point of this script is to check is ts3server and tsdns is running if not then restart them both if so then wait 15 seconds and start again and ill look into the respawn thing @steeldriver – ImpossibleMushroom Jan 13 '17 at 0:40