postrun-query revision 8283
10139N/A#!/bin/ksh
12199N/A#
10139N/A# Script for investigating postponed post-installation jobs submitted
10139N/A# using postrun
10139N/A#
10139N/A# CDDL HEADER START
10139N/A#
10139N/A# The contents of this file are subject to the terms of the
10139N/A# Common Development and Distribution License, Version 1.0 only
10139N/A# (the "License"). You may not use this file except in compliance
10139N/A# with the License.
12882N/A#
11991N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10139N/A# or http://www.opensolaris.org/os/licensing.
10139N/A# See the License for the specific language governing permissions
10139N/A# and limitations under the License.
12246N/A#
10139N/A# When distributing Covered Code, include this CDDL HEADER in each
10139N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
10139N/A# If applicable, add the following below this CDDL HEADER, with the
13529N/A# fields enclosed by brackets "[]" replaced with your own identifying
12905N/A# information: Portions Copyright [yyyy] [name of copyright owner]
12905N/A#
10139N/A# CDDL HEADER END
10139N/A#
10139N/A#
10139N/A# Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
10139N/A# Use is subject to license terms.
10139N/A#
10139N/A
10139N/Aexport PATH=/usr/bin
10139N/ALC_ALL=C
10139N/Aexport LC_ALL
10139N/AMYDIR=$(cd $(dirname $0); pwd)
10139N/ASPOOLDIR="$MYDIR/../../var/spool/postrun"
10139N/A
10139N/Ausage() {
10139N/A echo 'Usage: postrun-query [options]'
10139N/A echo
10139N/A echo 'Options:'
10139N/A echo ' -c <class>, --class <class>'
10139N/A echo ' Only consider jobs the belong to class <class>'
10139N/A echo
10139N/A echo ' -e, --exists'
10139N/A echo ' return 0 if spooled jobs exist 1 otherwise'
10139N/A echo
10139N/A echo ' -n, --count'
10139N/A echo ' print the number of spooled jobs only. The default'
10139N/A echo ' behaviour is to list all jobs'
10139N/A echo
10139N/A echo ' -j <job>, --job <job>'
10139N/A echo ' display job number <job>'
10139N/A echo
10139N/A echo ' -h, -?, --help'
10139N/A echo ' Display this help'
10139N/A exit 1
10139N/A}
10139N/A
10139N/A
10139N/Apostrun_query_count=no
10139N/Apostrun_query_class=
10139N/Apostrun_query_check_exists=no
10139N/Apostrun_query_job=
10139N/A
10139N/A# process the command line
10139N/Awhile [ $# -gt 0 ]; do
10139N/A case "$1" in
10139N/A -h|-\?|--help)
13547N/A usage
13547N/A ;;
12905N/A -e|--exists)
10139N/A postrun_query_check_exists=yes
10139N/A ;;
10139N/A -n|--count)
10139N/A postrun_query_count=yes
10139N/A ;;
10139N/A -j|--job)
10139N/A opt="$1"
10139N/A if [ $# == 0 ]; then
10139N/A echo "postrun-query: error: argument expected after $opt"
10139N/A exit 1
10139N/A fi
10139N/A shift
10139N/A postrun_query_job="$1"
10307N/A ;;
10139N/A -c|--class)
10392N/A opt="$1"
10139N/A if [ $# == 0 ]; then
10139N/A echo "postrun-query: error: argument expected after $opt"
10139N/A exit 1
10139N/A fi
12911N/A shift
10318N/A postrun_query_class="$1\$"
10318N/A ;;
10139N/A --)
10139N/A break
10318N/A ;;
10139N/A *)
10139N/A echo "postrun: error: invalid argument: $1"
10139N/A exit 1
10139N/A ;;
10139N/A esac
10139N/A shift
10139N/Adone
10139N/A
10139N/A# exit 0 if jobs exist
10139N/A# exit 1 if no jobs exist
10139N/Aif [ $postrun_query_check_exists = yes ]; then
10139N/A grep "^class: $postrun_query_class" $SPOOLDIR/*.ctrl >/dev/null 2>&1 \
10139N/A && exit 0 || exit 1
10139N/Afi
10139N/A
10139N/A# print the # of jobs
10139N/Aif [ $postrun_query_count = yes ]; then
10139N/A grep -l "^class: $postrun_query_class" $SPOOLDIR/*.ctrl 2>/dev/null \
10139N/A | wc -l
10139N/A exit 0
10139N/Afi
10139N/A
10139N/A# print info about a job
10139N/Aif [ "x$postrun_query_job" != x ]; then
10139N/A test -f $SPOOLDIR/$postrun_query_job.ctrl && \
10139N/A job_details="`cat $SPOOLDIR/$postrun_query_job.ctrl`" && \
10139N/A job_commands="`cat $SPOOLDIR/$postrun_query_job.cmd`" || {
10139N/A echo "postrun-query: job $postrun_query_job not found"
10139N/A exit 1
10139N/A }
10139N/A echo Job $postrun_query_job
13547N/A echo "Submitted on`echo "$job_details" | grep '^submit_time:' | cut -f2- -d:`"
13547N/A echo "Belongs to package(s):`echo "$job_details" | grep pkginst: | cut -f2 -d:`"
13547N/A classes=`echo "$job_details" | grep '^class:' | cut -f2 -d:`
13531N/A classes=`echo $classes | sed -e 's/ /,/g'`
13531N/A echo "Class(es): $classes"
13394N/A echo "---commands follow---"
13394N/A echo "$job_commands"
12911N/A echo "---end of commands---"
12911N/A exit 0
12905N/Afi
12905N/A
12905N/A# list the jobs
12246N/Actrls=`grep -l "^class: $postrun_query_class" $SPOOLDIR/*.ctrl 2>/dev/null`
12246N/Atest "x$ctrls" = x \
12246N/A && echo "No spooled jobs found." \
12246N/A || echo "Job # Class(es) Package(s)"
12223N/Afor ctrl in $ctrls; do
12223N/A nr=`basename $ctrl .ctrl`
12223N/A classes=`grep '^class:' $ctrl | cut -f2 -d:`
12199N/A classes=`echo $classes | sed -e 's/ /,/g'`
12199N/A pkginst=`grep '^pkginst:' $ctrl | cut -f2 -d:`
11991N/A echo "$nr $classes $pkginst"
11991N/Adone
11006N/A