Moved thread to servers forum.
Printable View
Moved thread to servers forum.
give this a try. it ought to be able to find the TS server, if running, and if not, start it up properly.
once you've created this script, made it executable, and tested it, you can make it a cron job.Code:#!/bin/bash
D1=$(readlink -f "$0")
BINARYPATH="$(dirname "${D1}")"
cd "${BINARYPATH}"
LIBRARYPATH="$(pwd)"
if [ -e "ts3server_linux_x86" ]; then
BINARYNAME="ts3server_linux_x86"
elif [ -e "ts3server_linux_amd64" ]; then
BINARYNAME="ts3server_linux_amd64"
elif [ -e "ts3server_freebsd_x86" ]; then
BINARYNAME="ts3server_freebsd_x86"
elif [ -e "ts3server_freebsd_amd64" ]; then
BINARYNAME="ts3server_freebsd_amd64"
else
echo "Could not locate binary file, aborting"
exit 5
fi
echo "TeamSpeak binary: $BINARYNAME"
pid=$(/sbin/pidof -x $BINARYNAME)
if [ -n "$pid" ]; then
echo "TeamSpeak (pid $pid) is running"
exit 0
else
echo "TeamSpeak is not running"
fi
printf "Starting TeamSpeak: "
cd /home/joaogl/Documents/ts3/ts3
sh ./ts3s.sh
rc=$?
if [ $? -eq 0 ]; then
echo OK
else
echo FAILED
fi
exit $rc
so its like:
thant add this command:Code:nano /bin/bash
Code:D1=$(readlink -f "$0")
BINARYPATH="$(dirname "${D1}")"
cd "${BINARYPATH}"
LIBRARYPATH="$(pwd)"
if [ -e "ts3server_linux_x86" ]; then
BINARYNAME="ts3server_linux_x86"
elif [ -e "ts3server_linux_amd64" ]; then
BINARYNAME="ts3server_linux_amd64"
elif [ -e "ts3server_freebsd_x86" ]; then
BINARYNAME="ts3server_freebsd_x86"
elif [ -e "ts3server_freebsd_amd64" ]; then
BINARYNAME="ts3server_freebsd_amd64"
else
echo "Could not locate binary file, aborting"
exit 5
fi
echo "TeamSpeak binary: $BINARYNAME"
pid=$(/sbin/pidof -x $BINARYNAME)
if [ -n "$pid" ]; then
echo "TeamSpeak (pid $pid) is running"
exit 0
else
echo "TeamSpeak is not running"
fi
printf "Starting TeamSpeak: "
cd /home/joaogl/Documents/ts3/ts3
sh ./ts3s.sh
rc=$?
if [ $? -eq 0 ]; then
echo OK
else
echo FAILED
fi
exit $rc
is that right?
no, the first part of your command would open the /bin/bash binary in nano. not a lot of goodness there. you want to pass the name of a file that will be your cron script to the editor, e.g.:
then put all that other code into it.Code:nano /tmp/ts-cron.sh
also, at the top of the script, put this on the very first line:
this tells the script what command interpreter to use, if run with via "./" (as opposed to specifically calling it with the interpreter, e.g.: bash /tmp/ts-cron.sh).Code:#!/bin/bash
also, make sure it is executable, e.g.:
Code:chmod +x /tmp/ts-cron.sh
ive done every thing:
and in the file is this:Code:[joaogl@localhost ~]$ nano /tmp/ts-cron.sh
[joaogl@localhost ~]$ chmod +x /tmp/ts-cron.sh
[joaogl@localhost ~]$
and as you can see:Code:#!/bin/bash
D1=$(readlink -f "$0")
BINARYPATH="$(dirname "${D1}")"
cd "${BINARYPATH}"
LIBRARYPATH="$(pwd)"
if [ -e "ts3server_linux_x86" ]; then
BINARYNAME="ts3server_linux_x86"
elif [ -e "ts3server_linux_amd64" ]; then
BINARYNAME="ts3server_linux_amd64"
elif [ -e "ts3server_freebsd_x86" ]; then
BINARYNAME="ts3server_freebsd_x86"
elif [ -e "ts3server_freebsd_amd64" ]; then
BINARYNAME="ts3server_freebsd_amd64"
else
echo "Could not locate binary file, aborting"
exit 5
fi
echo "TeamSpeak binary: $BINARYNAME"
pid=$(/sbin/pidof -x $BINARYNAME)
if [ -n "$pid" ]; then
echo "TeamSpeak (pid $pid) is running"
exit 0
else
echo "TeamSpeak is not running"
fi
printf "Starting TeamSpeak: "
cd /home/joaogl/Documents/ts3/ts3
sh ./ts3s.sh
rc=$?
if [ $? -eq 0 ]; then
echo OK
else
echo FAILED
fi
exit $rc
so.... some things is roung i thinkCode:[joaogl@localhost ~]$ chmod +x /tmp/ts-cron.sh
[joaogl@localhost ~]$
that all looks good, why do you say something is wrong? we have not set up cron to run it yet, if that is what you mean.
first, run it from the command line, as a test - to make sure that it works. run it like this:
report the output of the command here.Code:cd /tmp
./ts-cron.sh
now i think is wrong :D
Code:[joaogl@localhost tmp]$ ./ts-cron.sh
Could not locate binary file, aborting
okay, you've either got to put your ts-cron.sh script in the same directory where the binary is located, or hard-code the path to the binary in the script.
let's do the former. so if the binary is in the path /home/joaogl/Documents/ts3/ts3 (which i think it is, but you should know), then do:
then run the script, e.g.:Code:mv /tmp/ts-cron.sh /home/joaogl/Documents/ts3/ts3/
is that better?Code:cd /home/joaogl/Documents/ts3/ts3
./ts-cron.sh
ok now its fine:
Code:[joaogl@localhost ts3]$ ./ts-cron.sh
TeamSpeak binary: ts3server_linux_x86
TeamSpeak is not running
Starting TeamSpeak: Usage: ./ts3s.sh {start|stop|restart|status}
OK
[joaogl@localhost ts3]$
now to test this can i just do: sh ts3s.sh stop and it will open again?
actually it didnt work but i've already fix it:
Code:[joaogl@localhost ts3]$ ./ts-cron.sh
TeamSpeak binary: ts3server_linux_x86
TeamSpeak is not running
Starting TeamSpeak: Starting the TeamSpeak 3 server
TeamSpeak 3 server started, for details please view the log file
OK
[joaogl@localhost ts3]$
Code:[joaogl@localhost ts3]$ ./ts-cron.sh
TeamSpeak binary: ts3server_linux_x86
TeamSpeak (pid 11756) is running
just becouse of thatCode:printf "Starting TeamSpeak: "
cd /home/joaogl/Documents/ts3/ts3
sh ./ts3s.sh start
rc=$?
if [ $? -eq 0 ]; then