Bacula-users

[Bacula-users] Retrieving Client Adress from bacula-dir.conf

2011-02-09 10:40:05
Subject: [Bacula-users] Retrieving Client Adress from bacula-dir.conf
From: Jan Lentfer <Jan.Lentfer AT web DOT de>
To: <bacula-users AT lists.sourceforge DOT net>
Date: Wed, 09 Feb 2011 16:37:07 +0100
Hi,

we had the discussion here latley on how to retrieve the client's adress
from bacula-dir.conf for RunAfter/Before scripts. I got some awk here that
works for me that I'd like to share:

BEGIN       {RS="}\n"; FS = "\n";}
/Client[[:space:]]+{/ {
    found = 0;
    for (i = 1; i <= NF; i++) {
        if ($i ~ /Name/) {
            split ($i, nameinfo, "[[:space:]]*=[[:space:]]*");
            if (nameinfo[2] == name) {
                found = 1;
            }
        }
        if ($i ~ /Address/ && found == 1) {
            split ($i, addressinfo, "[[:space:]]*=[[:space:]]*");
            address = addressinfo[2];
            if (address ~ /(^[[:space:]]+)|([[:space:]]+$)/) {
                gsub(/^[[:space:]]+/, "", address);
                gsub(/[[:space:]]+$/, "", address);
            }

            break;
        }
    }
    if (found)
        printf ("%s\n", address);
}
END         {}

It can be called like this:
awk -v name=<CLIENT NAME> -f <script_name> /path/to/bacula-dir.conf

I use this together with %c to retrieve the Client's address.

Credits for this need to go to my fellow DragonFly BSD colleague Joe
Talbott, who put this together for me as my awk capabilites are a little
limited :)

Hope this of use to others, too.

Jan

--- 
professional: http://www.oscar-consult.de
private: http://neslonek.homeunix.org/drupal/

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users

<Prev in Thread] Current Thread [Next in Thread>