]> git.sur5r.net Git - bacula/bacula/blob - bacula/examples/next_tape.sh
- Use different share mode when opening files on WinMe/98/95 since
[bacula/bacula] / bacula / examples / next_tape.sh
1 #!/bin/bash
2 #
3 # A script which kicks out messages if a new tape is required for the next job. 
4 # It may be used as RunAfterJob script and it works fine for me. 
5 # Maybe someone considers it useful or has some ideas to improve it.
6 #
7 # Contributed by Dirk grosse Osterhues <digo@rbg.informatik.tu-darmstadt.de>
8 #
9 # select language: english (en) or german (de)
10 LANG="en"
11 # reciepient-address for notification
12 MAILTO_ADDR="your-email-address"
13 # bcc-address for notification
14 BCC_ADDR="email-address"
15 # directory for temp-files
16 TEMP_DIR="/tmp/bacula"
17 # bacula's console.conf
18 CONSOLE_CONF=/etc/bacula/bconsole.conf
19 ############################################
20
21 # test if console.conf exists
22 if [ ! -f $CONSOLE_CONF ]; then
23         echo "You need to reconfigure varible \$CONSOLE_CONF"
24         exit 1
25 fi
26 # get todays tape
27 director_output() {
28 /usr/sbin/bacula-console -c $CONSOLE_CONF <<EOF
29 status dir
30 quit
31 EOF
32 }
33 TODAY=`date +%d.%m.%y`
34 YESTERDAY=`date +%d.%m.%y -d yesterday`
35 HOST=`hostname -f`
36
37 # /root/NEXT-TAPE-$TODAY will be /root/NEXT-TAPE-$YESTERDAY tomorrow ;)
38 TAPE_TODAY=`director_output|awk '/^Scheduled Jobs/ { getline; getline; getline; print $6;exit }'`
39
40 # did it alreadly run for at least one time?
41 if test -f $TEMP_DIR/NEXT-TAPE-$YESTERDAY ; then
42         TAPE_YESTERDAY=`cat $TEMP_DIR/NEXT-TAPE-"$YESTERDAY"`
43 else
44         TAPE_YESTERDAY=$TAPE_TODAY
45         echo $TAPE_YESTERDAY>$TEMP_DIR/NEXT-TAPE-$YESTERDAY
46 fi
47 echo $TAPE_TODAY>$TEMP_DIR/NEXT-TAPE-$TODAY
48
49 # definition of language-dependent variables
50 case $LANG in
51         de)
52         MAIL_SUBJECT="[Bacula] Bitte Tape wechslen!"
53         MAIL_BODY="Nachricht von Bacula-Backup-System auf $HOST:\
54                 \n\n Tape entfernen:\t\""$TAPE_YESTERDAY"\"\
55                 \n Tape einlegen: \t\""$TAPE_TODAY"\""
56         ;;
57         en)
58         MAIL_SUBJECT="[Bacula] Please replace Tape tonight!"
59         MAIL_BODY="Message from bacula-backup-service on $HOST:\
60                 \n\n Remove Tape:\t\""$TAPE_YESTERDAY"\"\
61                 \n Insert Tape:\t\""$TAPE_TODAY"\""
62         ;;
63 esac
64
65 # send notification
66 if [ $TAPE_TODAY != $TAPE_YESTERDAY ] ; then
67         echo -e $MAIL_BODY | mail -a "X-Bacula: Tape-Notifier on $HOST" -s "`echo $MAIL_SUBJECT`" -b $BCC_ADDR $MAILTO_ADDR
68 fi
69
70 # remove older temp-files
71 find $TEMP_DIR -type f -name NEXT-TAPE-\*| while read I; do
72         TAPE_FILE=${I##/tmp/bacula/}
73         if [ $TAPE_FILE ]; then
74                 if [ $TAPE_FILE != NEXT-TAPE-$TODAY ] && [ $TAPE_FILE != NEXT-TAPE-$YESTERDAY ]; then
75                         rm  $TEMP_DIR/$TAPE_FILE
76                 fi
77         fi
78 done