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