# The labels of the virtual barcode reader are located in the BARCODE_FILE
SIMULATE_BARCODE=true
BARCODE_FILE=/usr/local/etc/bacula-barcodes
+TMPDIR=/tmp
+
+make_temp_file()
+{
+ TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+ if test $? -ne 0 || test x${TMPFILE} = x; then
+ TMPFILE="${TMPDIR}/mtx$1.$$"
+ if test -f ${TMPFILE}; then
+ echo "ERROR: Temp file security problem on: ${TMPFILE}"
+ exit 1
+ fi
+ fi
+}
me=$(basename $0)
loaded)
# echo "Request loaded"
- ${MTX} -f ${CHANGER} status -S > /tmp/mtx.$$
+ make_temp_file
+ ${MTX} -f ${CHANGER} status -S > ${TMPFILE}
rtn=$?
- cat /tmp/mtx.$$ | grep "^drive ${DRIVE}: <FULL>" | awk '{print $6+1}' | tr -d ">"
- cat /tmp/mtx.$$ | grep "^drive ${DRIVE}: source: <>" | awk "{print 0}"
- rm -f /tmp/mtx.$$
+ cat ${TMPFILE} | grep "^drive ${DRIVE}: <FULL>" | awk '{print $6+1}' | tr -d ">"
+ cat ${TMPFILE} | grep "^drive ${DRIVE}: source: <>" | awk "{print 0}"
+ rm -f ${TMPFILE}
exit $rtn
;;
SIMULATE_BARCODE=true
BARCODE_FILE=/usr/local/etc/bacula-barcodes
+TMPDIR=/tmp
+
+make_temp_file()
+{
+ TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+ if test $? -ne 0 || test x${TMPFILE} = x; then
+ TMPFILE="${TMPDIR}/mtx$1.$$"
+ if test -f ${TMPFILE}; then
+ echo "ERROR: Temp file security problem on: ${TMPFILE}"
+ exit 1
+ fi
+ fi
+}
+
+
me=$(basename $0)
fullpath_me=$0
loaded)
# echo "Request loaded"
- ${MTX} -f ${CHANGER} status -S > /tmp/mtx.$$
+ make_temp_file
+ ${MTX} -f ${CHANGER} status -S > ${TMPFILE}
rtn=$?
- cat /tmp/mtx.$$ | grep "^slot .: <ACCESS>" | awk '{print $2+1}' | tr -d ":"
- drive=`cat /tmp/mtx.$$ | grep "^drive .: <ACCESS>"`
+ cat ${TMPFILE} | grep "^slot .: <ACCESS>" | awk '{print $2+1}' | tr -d ":"
+ drive=`cat ${TMPFILE}| grep "^drive .: <ACCESS>"`
if [ -n "$drive" ]; then
echo 0
fi
- rm -f /tmp/mtx.$$
+ rm -f ${TMPFILE}
exit $rtn
;;
MTX=/lysator/bin/mtx
LOCKDIR=/tmp
+TMPDIR=/tmp
+
+make_temp_file()
+{
+ TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+ if test $? -ne 0 || test x${TMPFILE} = x; then
+ TMPFILE="${TMPDIR}/mtx$1.$$"
+ if test -f ${TMPFILE}; then
+ echo "ERROR: Temp file security problem on: ${TMPFILE}"
+ exit 1
+ fi
+ fi
+}
+
+
if test $# -lt 2 ; then
echo "usage: mtx-changer ctl-device command slot archive-device drive"
echo " Insufficient number of arguments arguments given."
LOCKFILE="${LOCKDIR}/mtx-changer:`echo $ctl | tr / _'"
changer_lock() {
- echo "$$" >$LOCKFILE.$$
+ make_temp_file lock
+ echo "$$" >${TMPFILE}
- while ! ln -n $LOCKFILE.$$ $LOCKFILE 2>/dev/null; do
+ while ! ln -n ${TMPFILE} $LOCKFILE 2>/dev/null; do
echo "$0: changer lock busy, retrying in 30 seconds..."
sleep 30
done
- rm $LOCKFILE.$$
+ rm ${TMPFILE}
}
changer_unlock() {
;;
loaded)
- ${MTX} -f $ctl status >/tmp/mtx.$$
+ make_temp_file
+ ${MTX} -f $ctl status >${TMPFILE}
rtn=$?
- cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
- cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
- rm -f /tmp/mtx.$$
+ cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
+ cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
+ rm -f ${TMPFILE}
changer_unlock $ctl
exit $rtn
;;
######################### Functions
+TMPDIR=/tmp
+
+make_temp_file()
+{
+ TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+ if test $? -ne 0 || test x${TMPFILE} = x; then
+ TMPFILE="${TMPDIR}/mtx$1.$$"
+ if test -f ${TMPFILE}; then
+ echo "ERROR: Temp file security problem on: ${TMPFILE}"
+ exit 1
+ fi
+ fi
+}
+
+
loaded)
echo "Request loaded, DREW YOU HAVEN'T IMPLEMENTED YET!!!!"
- ${MTX} -f $1 status >/tmp/mtx.$$
+ make_temp_file
+ ${MTX} -f $1 status >${TMPFILE}
rtn=$?
- cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print
+ cat ${TMPFILE} | grep "^Data Transfer Element 0:Full" | awk "{print
\$7}"
- cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Empty" | awk "{print
+ cat ${TMPFILE} | grep "^Data Transfer Element 0:Empty" | awk "{print
0}"
-# cat /tmp/mtx.$$ | grep "^Data Transfer Element 1:Full" | awk "{print
+# cat ${TMPFILE} | grep "^Data Transfer Element 1:Full" | awk "{print
\$7}"
-# cat /tmp/mtx.$$ | grep "^Data Transfer Element 1:Empty" | awk
+# cat ${TMPFILE} | grep "^Data Transfer Element 1:Empty" | awk
"{print 0}"
- rm -f /tmp/mtx.$$
+ rm -f ${TMPFILE}
echo "mtx-changer returning value: $rtn"
exit $rtn
MTX=/usr/sbin/mtx
+TMPDIR=/tmp
+
+make_temp_file()
+{
+ TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+ if test $? -ne 0 || test x${TMPFILE} = x; then
+ TMPFILE="${TMPDIR}/mtx$1.$$"
+ if test -f ${TMPFILE}; then
+ echo "ERROR: Temp file security problem on: ${TMPFILE}"
+ exit 1
+ fi
+ fi
+}
+
+
if test $# -lt 2 ; then
echo "usage: mtx-changer ctl-device command slot archive-device drive"
echo " Insufficient number of arguments arguments given."
;;
loaded)
- tempfile=`mktemp -t` || exit 33
- ${MTX} -f $ctl status > $tempfile
+ make_temp_file
+ ${MTX} -f $ctl status > ${TMPFILE}
rtn=$?
- cat $tempfile | grep "^Data Transfer Element $drive:Full" | awk '{print $7}'
- cat $tempfile | grep "^Data Transfer Element $drive:Empty" | awk '{print 0}'
- rm -f $tempfile
+ cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full" | awk '{print $7}'
+ cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk '{print 0}'
+ rm -f ${TMPFILE}
exit $rtn
;;
#TAPEDRIVE0 holds the device/name of your 1st and only DLT drive (Bacula supports only 1 drive currently)
#
#Read TAPEDRIVE from command line parameters
+
+TMPDIR=/tmp
+
+make_temp_file()
+{
+ TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+ if test $? -ne 0 || test x${TMPFILE} = x; then
+ TMPFILE="${TMPDIR}/mtx$1.$$"
+ if test -f ${TMPFILE}; then
+ echo "ERROR: Temp file security problem on: ${TMPFILE}"
+ exit 1
+ fi
+ fi
+}
+
+
+
if [ -z "$4" ] ; then
TAPEDRIVE0=/dev/st0
else
#
#Check if you want to fool me
if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Checking if drive is loaded before we unload. I Request loaded" ; fi
- mtx -f $1 status >/tmp/mtx.$$
+ make_temp_file
+ mtx -f $1 status >${TMPFILE}
rm -f /tmp/mtxloaded
- cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
- rm -f /tmp/mtx.$$
+ cat ${TMPFILE} | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
+ rm -f ${TMPFILE}
read LOADEDVOL </tmp/mtxloaded
if [ -z "$LOADEDVOL" ] ; then
LOADEDVOL=0
load)
#Let's check if drive is loaded before we load it
if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Checking if drive is loaded before we load. I Request loaded" ; fi
- mtx -f $1 status >/tmp/mtx.$$
+ make_temp_file
+ mtx -f $1 status >${TMPFILE}
rm -f /tmp/mtxloaded
- cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
- rm -f /tmp/mtx.$$
+ cat ${TMPFILE}| grep "^Data Transfer Element 0:Full" | awk "{print \$7}" > /tmp/mtxloaded
+ rm -f ${TMPFILE}
read LOADEDVOL </tmp/mtxloaded
if [ -z "$LOADEDVOL" ] ; then
LOADEDVOL=0
loaded)
if [ $MTXCHVERBOSE -eq 1 ] ; then echo "mtx-changer: Request loaded" ; fi
- mtx -f $1 status >/tmp/mtx.$$
- cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Full" | awk "{print \$7}"
- cat /tmp/mtx.$$ | grep "^Data Transfer Element 0:Empty" | awk "{print 0}"
- rm -f /tmp/mtx.$$
+ make_temp_file
+ mtx -f $1 status >${TMPFILE}
+ cat ${TMPFILE} | grep "^Data Transfer Element 0:Full" | awk "{print \$7}"
+ cat ${TMPFILE} | grep "^Data Transfer Element 0:Empty" | awk "{print 0}"
+ rm -f ${TMPFILE}
;;
slots)
MTX=mtx
+TMPDIR=/tmp
+
+make_temp_file()
+{
+ TMPFILE=`mktemp ${TMPDIR}/mtx$1.XXXXXXXXXX 2> /dev/null`
+ if test $? -ne 0 || test x${TMPFILE} = x; then
+ TMPFILE="${TMPDIR}/mtx$1.$$"
+ if test -f ${TMPFILE}; then
+ echo "ERROR: Temp file security problem on: ${TMPFILE}"
+ exit 1
+ fi
+ fi
+}
+
+
+
#
# The purpose of this function to wait a maximum
;;
loaded)
- ${MTX} -f $ctl status >/tmp/mtx.$$
+ make_temp_file
+ ${MTX} -f $ctl status >${TMPFILE}
rtn=$?
- cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
- cat /tmp/mtx.$$ | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
- rm -f /tmp/mtx.$$
+ cat ${TMPFILE} | grep "^Data Transfer Element $drive:Full" | awk "{print \$7}"
+ cat ${TMPFILE} | grep "^Data Transfer Element $drive:Empty" | awk "{print 0}"
+ rm -f ${TMPFILE}
exit $rtn
;;