- 论坛徽章:
- 0
|
#!/bin/sh
# -*- mode: shell-script; -*-
# $Id: $
#
# Copyright 2005 Vision Solutions, Inc.
#
# db2_heartbeat -- This script will check if db2 is running
#
# Usage: db2_heartbeat
#
# This script checks to see if db2 is running. It assumes that it is
# not there if there has not been a response in 3 seconds. This script
# can be run by any user, as the correct environment is set internally
# to this script.
#
# This script will end with an exit status of 0 if it runs
# successfully. In all other circumstances the script will end
# with a non-zero exit status.
# Setup
cmdname=`basename $0`
directory=`dirname $0`
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
export PATH
# Useful functions.
function usage {
die "usage: $cmdname [ -p partition ] [ -i db2instname ]
Check to see if the db2 is running.
The partition number must be an integer or a comma separated
list of integers (e.g., 0,1,2). There can be no spaces in the
list. Note that the exit value will be the value of the
partition with the most error. That is, if partition 0 is
available and partition 1 is not available then checking
partitions 0 and 1 will result in an exit code of \"1\".
The instance name can be passed in the environment variable
DB2_IUSER. If DB2_IUSER is set then the -i option is not
needed. Otherwise, it is required.
If all checked partitions are available exit with 0, if not exit
with 1."
}
function die { warn "$@"; exit 1; }
function warn { echo "$@" >&2; }
####################################################################
#
# Start Here
#
####################################################################
# The default partition number is 0. If partition is set then
# that partition is checked.
partition=0
while getopts p:i: opt; do
case "$opt" in
p) partition="$OPTARG" ;;
i) export DB2_IUSER="$OPTARG" ;;
?) usage ;;
esac
done
shift `expr $OPTIND - 1`
# DB2_IUSER can come from the environment or from the command line
# But it must be set one way or the other.
[ -z "$DB2_IUSER" ] && usage
eval db2gcf=~"$DB2_IUSER"/sqllib/bin/db2gcf
[ -x "$db2gcf" ] || exit 1
eval $db2gcf -s -p $partition -i $DB2_IUSER >/dev/null 2>&1
# |
|