[conquest] Improved AWK script for monitoring metaservers

Jon Trulson jon at radscan.com
Tue Jun 23 03:18:20 MDT 2009


On Mon, 22 Jun 2009, madams at phantomware.ca wrote:

> For the record, here is an improved AWK script that accepts some
> variables via the command line.
>
> I use it like this in my crontab:
>
> @hourly    ~/bin/scripts/conquest-metaserver-monitor -v email=matt,tamarella
>
> But you can also specify an optional metaserver name & port number
> using additional -v arguments.
>
>
> Hope someone finds this useful,
>
> Matt
>

   I'll add it to contrib in the repo along with a readme.  Thanks!

   PS: didn't even know you could do stuff like that with awk :)


> ===File ~/bin/scripts/conquest-metaserver-monitor===========
> #!/usr/bin/awk -f
> #
> # Queries a Conquest metaserver for games with active players
> # See http://conquest.radscan.com/conquest.html for more info
> #
> # Accepts the following -v parameters
> #   server (name of metaserver to query)
> #   port   (port of metaserver to query)
> #   email  (email addresses to notify, separated by commas)
> #
> # Fields
> # =====================================================================
> #  ?  SERVER_HOST  PORT  NAME  VERSION  MOTD  MAX_SLOTS  ACTIVE#  VACANT#  ROBOT#  ?  ?  CONTACT_EMAIL  LOCALTIME
> #  1  2            3     4     5        6     7          8        9        10      11 12 13             14
> #
>
> BEGIN {
>    if (!server)
>        server = "conquest.radscan.com"
>    if (!port)
>        port = "1700"
>
>    if (!email) {
>        printf "%s: You must set the email addresses to notify using `-v email=addr1,addr2'\n", ARGV[0] > "/dev/stderr"
>        exit
>    }
>
>    FS="|"
>    NetService = "/inet/tcp/0/" server "/" port
>    print "name" |& NetService
>
>    while ((NetService |& getline) > 0) {
>        if ($8 > 0) {
>            printf "echo \"Conquest server has %d/%d ACTIVE players (%d VACANT, %d ROBOT)\nconquestgl -f -s %s:%d\n\n\" | mail -s \"ACTIVE CONQUEST GAME\" %s",
>                $8, $7, $9, $10, $2, $3, email | "/bin/sh"
>            close("/bin/sh")
>        }
>    }
>
>    close(NetService)
> }
> ============================================================
>

-- 
Happy cheese in fear                 | Jon Trulson
against oppressor, rebel!            | mailto:jon at radscan.com
Brocolli, hostage.       -Unknown    | A828 C19D A087 F20B DFED
                                      | 67C9 6F32 31AB E647 B345




More information about the Conquest mailing list