Bacula-users

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

2011-02-09 14:20:39
Subject: Re: [Bacula-users] Retrieving Client Adress from bacula-dir.conf
From: Martin Simmons <martin AT lispworks DOT com>
To: bacula-users AT lists.sourceforge DOT net
Date: Wed, 9 Feb 2011 19:17:12 GMT
>>>>> On Wed, 09 Feb 2011 16:37:07 +0100, Jan Lentfer said:
> 
> 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 :)

Here is a way that avoids dependency on the config file layout:

echo show client=<CLIENT NAME> | bconsole | sed -ne 's/^Client: .* address=\([^ 
]*\).*/\1/p'

__Martin

------------------------------------------------------------------------------
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>