Some suggestions:
- you aren't sending the process to the background, so there is no need for the if statement (which itself is also broken since the grep will see itself in the processlist and return true)
- shell scripts should generally have a .sh suffix
- the shebang is missing
- please use "while true" or "while :" instead of "while date" (date will generally return 0 so it will work. but it just doesn't make sense since the the loop isn't critically based on a working date binary , would be a shame if mangos doesn't start just because someone broke "date")
if all you want is a simple restarter that logs when it restarted, your script wound look fine like this:
#!/bin/bash
Daemon="worldd"
BinDir="/opt/MaNGOS/bin/"
LogDir="/opt/MaNGOS/log/"
if [[ $(ps -o command= -ae|egrep -c "[m]angos-${Daemon}") -gt 0 ]]
then echo "mangos-${Daemon} is already running, exiting"
exit 1
fi
######### End of Config ##########
while true
do # loop forever echo "(re)starting server at $(date +"%m-%d-%H:%M-%S")>> ${LogDir}${Daemon}_restart_log.txt
nice -n 20 ${BinDir}mangos-${Daemon}
sleep 5
done
checking for running processes works a bit better if you have mangos configured to write pidfiles, then you just have to check if the pid in the file is actually running (e.g. by checking /proc/$pid/cmdline)