Crazy Canucks wrote:
> Just wondering if anyone knows it is possible to query a server from a
> bash script, and if so, if you could point me in the right direction as
> to how to do it. I suppose if it isn't possible, I can always use a
> perl script to query the server and output the data to a file.
>
> Cheers, Drek
Yes, there might be a solution. This is a little script function (in
bash) to ping a server and return 0 if the server is online and 1 if the
server is gone. It uses the netcat command (nc) to send the request. It
waits just one second for the connection and one for the return value.
ping_server() {
SERVER=$1
PORT=${2:-27015}
RESULT=`echo -ne "\xFF\xFF\xFF\xFF\x69\x00" | \
nc -nu -q 1 -w 1 $SERVER $PORT`
RESULT=${RESULT:4:1}
if [ "$RESULT" == "j" ]; then
return 0
else
return 1
fi
}
Use it this way:
ping_server 127.0.0.1 27015
# or whatever ip / port your server has
if [ $? -eq 0 ]; then
echo "server online"
else
echo "server offline"
fi
More functions are described here:
http://developer.valvesoftware.com/wiki/Source_Server_Queries
Hope this could help.
Greets, Silent_Water
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlds_linux