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 |