I have a small crash detect script for a teamspeak server. The only issue is that I keep getting a syntaxt error about an unexpected end of file. I am not sure if I am missing something in this from all the guides I have been following. I have also ran dos2unix since I do alot of the coding in sublime text 2 on windows.
#!/bin/bash
TEAMSPEAK=`ps ax | grep ts3server_linux_amd64 | grep -v grep | wc -l`
if [ $TEAMSPEAK -eq 1 ]; then
exit
else
cd /home/ryahn/ts3
if [ -f ts3server.pid ]; then
rm -f ts3server.pid
echo "File here"
. ./home/minecraft/ts3/ts3server_startscript.sh start
fi
You are missing a fi
for outer if
condition.
Keep your code indented to understand it better:
if [ $TEAMSPEAK -eq 1 ]; then
exit
else
cd /home/ryahn/ts3
if [ -f ts3server.pid ]; then
rm -f ts3server.pid
echo "File here"
. ./home/minecraft/ts3/ts3server_startscript.sh start
fi
fi
btw you can shorten your piped commands using pgrep
:
TEAMSPEAK=$(pgrep -f ts3server_linux_amd64|wc -l)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.