Article Listing 1 Listing 2 Listing 3 Listing 4
Listing 5 Listing 6 Listing 7 Listing 8 Listing 9
Listing 10 Listing 11 Listing 12 Listing 13 Sidebar aug2004.tar

Listing 1 batch_zip

#!/bin/ksh

batch_size=1

case $(basename $0) in
batch_zip)
    semaphore_name=batch_zip
    zip_command=gzip
    ;;
batch_unzip)
    semaphore_name=batch_unzip
    zip_command=gunzip
    ;;
esac

while getopts n:s:z: option
do
    case $option in
    n) semaphore_name=$OPTARG ;;
    s) batch_size=$OPTARG ;;
    z) zip_command=$OPTARG ;;
    esac
done

shift $(( $OPTIND - 1 ))

semaphore -I $batch_size $semaphore_name

while [[ -n $1 ]]
do
    {
        semaphore -P $semaphore_name
        $zip_command $1
        semaphore -V $semaphore_name;
    } &
    shift 1
done