On Fri, Jan 10, 2003 at 11:14:55AM +0000, Pavel Rabel wrote:
> > > >Can amanda send a signal to my DLT IV to unload the tape after backups
> > > >are finished, so whoever goes back to swap tapes can just do it without
> > > >waiting to manually unload?
>  
> > For amdump this is easy.
> > 
> > I didn't find a way to do this for amflush.
> > 
> > You must start amflush in the forground in order to answer the
> > questions, and then it backgrounds itself. So you do not know when
> > amflush really ends.
> 
> You may try to run amflush with the -f switch.

Pavel, Sven, others ...

Check if the attached script will help.
I've called it "ampwait", AManda Process WAIT.

By default it checks every 60 seconds for a running amflush.
The period between checks (granularity) can be set with a "-g seconds" option
and the program to wait for can also be specified as a command line argument.

Any additional arguments are a program to execute upon completion of amflush.

An example of usage might be:

   $ amflush DailySet1
     <answer questions>

   $ ampwait -g 20 amflush amtape DailySet1 eject

Alternatively run just 'ampwait' which defaults to '-g 60 amflush' and
run the amtape command separately when ampwait completes.

HTH
jon
-- 
Jon H. LaBadie                  [EMAIL PROTECTED]
 JG Computing
 4455 Province Line Road        (609) 252-0159
 Princeton, NJ  08540-4322      (609) 683-7220 (fax)
#!/usr/bin/ksh
#!/usr/bin/bash

# flushwait:
# wait until a detached command like amflush has completed
# requires a POSIX compatible shell like ksh or bash
#
# Default program to wait for: amflush (specified with cmd line arg)
# Default checking granularity: 60 seconds (time between checks - specified with -g 
<seconds>)
# Default command to execute: none, but remaining arguments will be executed at end

# uncomment for debugging
# set -x
# PS4='[$LINENO] '

ProgName=${0##*/}

usage() {
    echo "Usage: ${ProgName} [-g <seconds between checks>] [prog to wait for [cmd to 
run]]" >&2
    exit 1
}

# defaults

ProgToWaitFor=amflush
Granularity=60

# check for -g option

case "${1}" in
-g)     Granularity=${2}
        shift
        shift
        ;;
-g*)    Granularity=${1#-g}
        shift
        ;;
-*|+*)  echo "${ProgName}: ${1}: Invalid option" >&2
        usage
        ;;
esac

# check that granularity is numeric

if echo "${Granularity}" | grep '^[0-9][0-9]*$' > /dev/null 2>&1
then
        :
else
        echo "${ProgName}: ${Granularity}: granularity must be an integer" >&2
        exit 1
fi

# check for alternate program to wait for instead of amflush

if [ "${1}" != "" ]
then
        ProgToWaitFor="${1}"
        shift
fi

# Any remaining arguments will be executed at end,
# after ProgToWaitFor completes

# It is assumed that ProgToWaitFor is already running
# Gets its process id number now.  There could be multiple
# instances; all must complete for this program to end

ProgPid=$(ps -e | grep "[ /]${ProgToWaitFor}$" | awk '{print $1}')


if [ "${ProgPid}" = "" ]
then
        echo "${ProgName}: '${ProgToWaitFor}': no instance of this program running" >&2
        exit 1
fi
# echo PID is $ProgPid # debugging info

# kill -0 tests for the existance of a the process
# both kill and sleep are builtin commands in most posix shells
# so no extra processes are generated by this loop

while kill -0 ${ProgPid} 2> /dev/null
do
        sleep ${Granularity}
done

# echo $ProgToWaitFor is complete

"${@}"


Reply via email to