Bacula-users

Re: [Bacula-users] Script for checking a client status

2009-04-28 15:34:25
Subject: Re: [Bacula-users] Script for checking a client status
From: Arno Lehmann <al AT its-lehmann DOT de>
To: bacula-users AT lists.sourceforge DOT net
Date: Tue, 28 Apr 2009 21:27:39 +0200
Hi,

28.04.2009 13:37, Personal Técnico wrote:
> Hi,
> 
> I check a client status before run a job with this script, called 
> "check-status-client.sh":
> 
> -------------------------------------
> #! /bin/bash
> bconsole <<FINAL_DATOS
> @output /var/log/bacula/$1 w

Why not something like 'echo "sta client=$1" | bconsole -c ... | grep 
-q ...' and check the return code? Much simpler and uses less resources.

Also, I'd be careful using /var/log as temporary storage. And a bit 
more quoting might be safer, too.

> status client=$1
> quit
> FINAL_DATOS
> 
> ESTADO_CLIENTE=""
> ESTADO_CLIENTE=`grep "Failed to connect to Client" /var/log/bacula/$i`

$i != $1

> if [ -z "$ESTADO_CLIENTE" ] ; then
>         exit 0  ## NO ERROR
> else
>         exit -1 ## HA HABIDO ERROR

Use exit 1. Bash uses unsigned bytes for exist status, i.e. values 
from 0..255. -1 == 255. Though this shouldn't be a problem, it's 
harder to read.

> fi
> -------------------------------------
> 
> Into job definition, we have something like this
> Job {
>      ...
>     Run Before Job = "/etc/bacula/scripts/check-status-client.sh '%c'"
>     ...
> }
> 
> 
> And file created into script (/var/log/bacula/$1)
> 
> Connecting to Client client-fd at X.Y.Z.72:9102
> Failed to connect to Client client-fd.
> ====
> You have messages.
> quit
> 
> With this result, script exit would be "-1" and job should be cancelled 
> and not tried to run...

I suppose the grep command doesn't do what you want because of the $i 
file name.

Better user a simple grep and 'exit $?' or even just the grep - the 
return code of the last command should be used as the scripts return code.

In any case, to debug this sort of problems,
1. Run them from the shell. If they don't behave as expected, run them 
with bash -x ... from the shell.
2. Add some progress logging to the script, for example add a 'echo 
"`/bin/date` grep found ${ESTADO_CLIENTE} and exited with $?" >> 
/tmp/bacula-script-log.out' after the grep line.

Otherwise, you'll never really understand what's happening. And we 
won't, too, so we can't help you :-)

> 
> In some document, I read if script exit with value different from 0 
> would mean script had exited with error and job won't run (in other 
> words, bacula would not try to connect with client).

Yup.

> However, I'm getting errors from a client that is not allowing access 
> (or is shut down), but messages from bacula shows following information:
> 
> 28-Apr 13:00 aosnap JobId 6195: No prior Full backup Job record found.
> 28-Apr 13:00 aosnap JobId 6195: No prior or suitable Full backup found 
> in catalog. Doing FULL backup.
> 28-Apr 13:01 aosnap JobId 6195: BeforeJob: run command 
> "/etc/bacula/scripts/check-status-client.sh 'client-fd'"
> 28-Apr 13:01 aosnap JobId 6195: BeforeJob: Connecting to Director 
> aosnap:9101
> 28-Apr 13:01 aosnap JobId 6195: BeforeJob: 1000 OK: aosnap Version: 
> 2.4.3 (10 October 2008)
> 28-Apr 13:01 aosnap JobId 6195: BeforeJob: Enter a period to cancel a 
> command.
> 28-Apr 13:01 aosnap JobId 6195: BeforeJob: @output /var/log/bacula/client w

Just my point - you need to know what happens in these four seconds...

> 28-Apr 13:04 aosnap JobId 6195: Start Backup JobId 6195, 
> Job=Backup-Client.2009-04-28_13.00.25
...
> It seems scripts it's running, although getting an "exit -1", bacula 
> tries to run backup.

Provide a bit more details of what the script does - not what it looks 
like - and we'll see...
> 
> Am I doing anything wrong?

Probably. The approach works correctly, at least. (Though I only ping 
the clients - if they are up but don't have a FD running, I want a 
loud error message...)

Arno

> Thanks.
> 
> 
> 
> ------------------------------------------------------------------------------
> Register Now & Save for Velocity, the Web Performance & Operations 
> Conference from O'Reilly Media. Velocity features a full day of 
> expert-led, hands-on workshops and two days of sessions from industry 
> leaders in dedicated Performance & Operations tracks. Use code vel09scf 
> and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
> _______________________________________________
> Bacula-users mailing list
> Bacula-users AT lists.sourceforge DOT net
> https://lists.sourceforge.net/lists/listinfo/bacula-users
> 

-- 
Arno Lehmann
IT-Service Lehmann
Sandstr. 6, 49080 Osnabrück
www.its-lehmann.de

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
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>