免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1375 | 回复: 0
打印 上一主题 下一主题

大家讨论一下explor脚本如何 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-07-26 18:50 |只看该作者 |倒序浏览
# cat explorer
#!/bin/ksh -p
#
#  explorer - System information data collector
#  $Id: //depot/dev/proactive/explorer3/bin/explorer#36 $
#

# Put variable assignments in environment
set -ka

# Open up umask
umask 022

# Do not create core files
ulimit -c 0

# Source main functions and parse arguments
DIR=`dirname $0`
if [ `echo ${DIR} | cut -c1` = "." ]
then
    # Make DIR absolute path
    cd ${DIR}
    DIR=`pwd`
fi
MAIN="`dirname ${DIR}`/lib/exp_main"
if [ -f "${MAIN}" ]
then
    . ${MAIN}
elif [ -f "/usr/lib/explorer/exp_main" ]
then
    . /usr/lib/explorer/exp_main
else
    echo "Unable to source exp_main"
    exit 1
fi

# Clean up on any of the given signals
trap 'clean' 1 2 3 14 15

# Set PATH based on EXP_PATH
export PATH=${EXP_PATH}
export CLASSPATH=${EXP_HOME}/java/fruid-scappclient.jar{EXP_HOME}/java/libfru.jar

export LD_LIBRARY_PATH=${EXP_LIB}
for lib in `echo ${EXP_PATH} | sed 's/:/ /g'`
do
    export LD_LIBRARY_PATH=`dirname ${lib}`/lib{LD_LIBRARY_PATH}
done

# Validate defaults file
ksh -p ${EXP_LIB}/exp_check

# Set start time
EXP_START=`date -u '+%Y.%m.%d.%H.%M'`
EXP_PID="$$"

# Print some useful debugging info to log
logfile "EXP_HOME=${EXP_HOME}"
logfile "EXP_LIB=${EXP_LIB}"
logfile "EXP_DEFAULTS=${EXP_DEFAULTS}"
logfile "ATH=${PATH}"
logfile "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
logfile "JAVA_HOME=${JAVA_HOME}"
logfile "CLASSPATH=${CLASSPATH}"

# Make sure EXP_ID is set
require 'test -n "${EXP_ID}"'
logfile NOTNOISE "explorer ID: ${EXP_ID}"
# logfile "local time: `date`"
TEXT=`gettext "local time: %s"`
date=`date`
TEXT=`printf "${TEXT}" "$date"`
logfile "${TEXT}"

# Must be Solaris 2.x, run as root and no previous EXP_TARGET
require "test `uname -s` = SunOS"
TEXT=`gettext "Must be run on SunOS 5.x"`
require "uname -r | grep '^5'" "${TEXT}"

# Attempt to use /usr/xpg4/bin/id, otherwise use /bin/id
TEXT=`gettext "Must be run as root"`
if [ -x "/usr/xpg4/bin/id" ]
then
    require "test `/usr/xpg4/bin/id -u` -eq 0" "${TEXT}"
else
    require '/bin/id | egrep -s -e "uid=0\("' "${TEXT}"
fi
require 'test -n "${EXP_TARGET}"'
TEXT=`gettext "EXP_TARGET=%s already exists"`
require 'test ! -d ${EXP_TARGET}' "${TEXT}"
require 'mkdir -p ${EXP_TARGET}'

# Redirect STDERR to stderr file above TARGET to allow for NFS collection
exec 2>; ${EXP_STDERR:=${EXP_TMPDIR}/stderr.${EXP_PID}}

# Log to /var/adm/messages
TEXT=`gettext "Explorer started"`
logger -p daemon.notice -t explorer "${TEXT}"

#
#  DATA GATHERING
#

# Loop through all scripts
if [ "${EXP_HOME}" = "/" ]
then
    for script in ${EXP_LIB}/tools/*
    do
        ksh -p $script $*
    done
else
    for script in ${EXP_HOME}/tools/*
    do
        ksh -p $script $*
    done
fi
# logfile NOTNOISE "data collection complete"
TEXT=`gettext "data collection complete"`
logfile NOTNOISE "${TEXT}"

#
#  POST PROCESSING
#

# Remove any zero length files from explorer output
find ${EXP_TARGET} -name '*.err' -size 0 -mount -exec rm {} \; 1>;/dev/null 2>;&1

# Post processing (IP address masking)
ksh -p ${EXP_LIB}/exp_postproc $*

# Set finish time
EXP_STOP=`date -u '+%Y.%m.%d.%H.%M'`

# Generate parse data
gen_parse_data

#
#  TRANSPORT
#

# Use system gzip before explorer gzip
EXP_GZIP=`type gzip 2>;&1 | sed 's/.*is //'`

if echo "${EXP_GZIP}" | egrep -s -e "not found"
then
    EXP_GZIP="${EXP_HOME}/bin/gzip.`uname -p`"
fi

EXP_FNAME=`basename ${EXP_TARGET}`
EXP_FILE="${EXP_FNAME}.tar.gz"

REL=`uname -r | nawk -F. '{ print $2 }'`
case ${REL} in
    3|4|5|6)
        # Pathname fix for tar (5.6 or lower)
        cd ${EXP_TARGET}/..
        MAX=`find ${EXP_FNAME} -type f -print | nawk '{ print length, $0 }' | sort -rn | head -1`
        DIRLEN=`dirname ${MAX} | nawk '{ print length }'`
        PATHLEN=`basename ${MAX} | nawk '{ print length }'`

        #
        # length of directory must be less than 155 and the
        # length of filename must be less than 100 characters
        # for tar to work correctly
        #
        if [ "${DIRLEN}" -ge 155 -o "${PATHLEN}" -ge 100 ]
        then
            cd ${EXP_TARGET}

            # Get list of directories to tar, create exclude file
            DIRS=""
            for dir in *
            do
                [ ! -d "$dir" ] && continue
                DIRS="${DIRS} $dir"
                echo "${EXP_FNAME}/$dir" >;>; ${EXP_TMPDIR}/exclude.${EXP_PID}
            done

            if [ -n "${DIRS}" ]
            then
                # Create tar of DIRS
                tar cf data.tar ${DIRS}
            fi

            # Tar and compress with gzip
            cd ${EXP_TMPDIR}
            tar cfX - ${EXP_TMPDIR}/exclude.${EXP_PID} ${EXP_FNAME} | ${EXP_GZIP} -c >;${EXP_FILE}
            # logfile "${EXP_FILE} created"
            TEXT=`gettext "%s created"`
            TEXT=`printf "${TEXT}" "${EXP_FILE}"`
            logfile "${TEXT}"

            # Remove data.tar from unpacked output
            rm -f ${EXP_TARGET}/data.tar
        else
            # Tar and compress with gzip
            cd ${EXP_TMPDIR}
            tar cf - ${EXP_FNAME} | ${EXP_GZIP} -c >;${EXP_FILE}
            # logfile "${EXP_FILE} created"
            TEXT=`gettext "%s created"`
            TEXT=`printf "${TEXT}" "${EXP_FILE}"`
            logfile "${TEXT}"
        fi
        ;;
    *)
        # Tar and compress with gzip
        cd ${EXP_TMPDIR}
        tar Ecf - ${EXP_FNAME} | ${EXP_GZIP} -c >;${EXP_FILE}
        # logfile "${EXP_FILE} created"
        TEXT=`gettext "%s created"`
        TEXT=`printf "${TEXT}" "${EXP_FILE}"`
        logfile "${TEXT}"
        ;;
esac

# Send the tarball
if [ -n "${EXP_TRANSPORT}" ]
then
    # Make sure EXP_REPLY is available to the transports
    ksh -p ${EXP_LIB}/exp_transport $*
fi

# Clean up
if [ -n "${EXP_STDERR}" ] && [ -s "${EXP_STDERR}" ]
then
    # logfile STDERROR "= = = stderr output from explorer = = ="
    TEXT=`gettext "= = = stderr output from explorer = = ="`
    logfile STDERROR "${TEXT}"
    while read line
    do
        logfile STDERROR "$line"
    done < "${EXP_STDERR}"
fi
test -n "${EXP_STDERR}" && rm -f ${EXP_STDERR}

# Remove old explorer runs if needed
DIR=`dirname ${EXP_TARGET}`
if [ -z "${EXP_KEEP}" ]
then
    # logfile NOTNOISE "removing previous explorers from ${DIR}"
    TEXT=`gettext "removing previous explorers from %s"`
    TEXT=`printf "${TEXT}" "${DIR}"`
    logfile NOTNOISE "${TEXT}"
    cd "${DIR}"

    for i in explorer.`hostid`.`uname -n`-*
    do
        # Keep the most current (directory and tarball)
        test "$i" = "${EXP_ID}"   && continue
        test "$i" = "${EXP_FILE}" && continue

        # Remove old directories
        rm -rf $i
    done
fi

# Log to /var/adm/messages
TEXT=`gettext "Explorer finished"`
logger -p daemon.notice -t explorer "${TEXT}"
logfile NOTNOISE "${TEXT}"
clean 1

exit 0
# ^[[B^[[B^[[B
^[[B^[[B^[[B: not found
#
# \
>;
#
#
#
# pwd
/opt/SUNWexplo/bin
# ls
capture.sparc   diskinfo.i386   explorer        gzip.sparc      t3client.i386
core_check.sh   diskinfo.sparc  gzip.i386       rprtfru.sparc   t3client.sparc
# cat explorer
#!/bin/ksh -p
#
#  explorer - System information data collector
#  $Id: //depot/dev/proactive/explorer3/bin/explorer#36 $
#

# Put variable assignments in environment
set -ka

# Open up umask
umask 022

# Do not create core files
ulimit -c 0

# Source main functions and parse arguments
DIR=`dirname $0`
if [ `echo ${DIR} | cut -c1` = "." ]
then
    # Make DIR absolute path
    cd ${DIR}
    DIR=`pwd`
fi
MAIN="`dirname ${DIR}`/lib/exp_main"
if [ -f "${MAIN}" ]
then
    . ${MAIN}
elif [ -f "/usr/lib/explorer/exp_main" ]
then
    . /usr/lib/explorer/exp_main
else
    echo "Unable to source exp_main"
    exit 1
fi

# Clean up on any of the given signals
trap 'clean' 1 2 3 14 15

# Set PATH based on EXP_PATH
export PATH=${EXP_PATH}
export CLASSPATH=${EXP_HOME}/java/fruid-scappclient.jar{EXP_HOME}/java/libfru.jar

export LD_LIBRARY_PATH=${EXP_LIB}
for lib in `echo ${EXP_PATH} | sed 's/:/ /g'`
do
    export LD_LIBRARY_PATH=`dirname ${lib}`/lib{LD_LIBRARY_PATH}
done

# Validate defaults file
ksh -p ${EXP_LIB}/exp_check

# Set start time
EXP_START=`date -u '+%Y.%m.%d.%H.%M'`
EXP_PID="$$"

# Print some useful debugging info to log
logfile "EXP_HOME=${EXP_HOME}"
logfile "EXP_LIB=${EXP_LIB}"
logfile "EXP_DEFAULTS=${EXP_DEFAULTS}"
logfile "ATH=${PATH}"
logfile "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
logfile "JAVA_HOME=${JAVA_HOME}"
logfile "CLASSPATH=${CLASSPATH}"

# Make sure EXP_ID is set
require 'test -n "${EXP_ID}"'
logfile NOTNOISE "explorer ID: ${EXP_ID}"
# logfile "local time: `date`"
TEXT=`gettext "local time: %s"`
date=`date`
TEXT=`printf "${TEXT}" "$date"`
logfile "${TEXT}"

# Must be Solaris 2.x, run as root and no previous EXP_TARGET
require "test `uname -s` = SunOS"
TEXT=`gettext "Must be run on SunOS 5.x"`
require "uname -r | grep '^5'" "${TEXT}"

# Attempt to use /usr/xpg4/bin/id, otherwise use /bin/id
TEXT=`gettext "Must be run as root"`
if [ -x "/usr/xpg4/bin/id" ]
then
    require "test `/usr/xpg4/bin/id -u` -eq 0" "${TEXT}"
else
    require '/bin/id | egrep -s -e "uid=0\("' "${TEXT}"
fi
require 'test -n "${EXP_TARGET}"'
TEXT=`gettext "EXP_TARGET=%s already exists"`
require 'test ! -d ${EXP_TARGET}' "${TEXT}"
require 'mkdir -p ${EXP_TARGET}'

# Redirect STDERR to stderr file above TARGET to allow for NFS collection
exec 2>; ${EXP_STDERR:=${EXP_TMPDIR}/stderr.${EXP_PID}}

# Log to /var/adm/messages
TEXT=`gettext "Explorer started"`
logger -p daemon.notice -t explorer "${TEXT}"

#
#  DATA GATHERING
#

# Loop through all scripts
if [ "${EXP_HOME}" = "/" ]
then
    for script in ${EXP_LIB}/tools/*
    do
        ksh -p $script $*
    done
else
    for script in ${EXP_HOME}/tools/*
    do
        ksh -p $script $*
    done
fi
# logfile NOTNOISE "data collection complete"
TEXT=`gettext "data collection complete"`
logfile NOTNOISE "${TEXT}"

#
#  POST PROCESSING
#

# Remove any zero length files from explorer output
find ${EXP_TARGET} -name '*.err' -size 0 -mount -exec rm {} \; 1>;/dev/null 2>;&1

# Post processing (IP address masking)
ksh -p ${EXP_LIB}/exp_postproc $*

# Set finish time
EXP_STOP=`date -u '+%Y.%m.%d.%H.%M'`

# Generate parse data
gen_parse_data

#
#  TRANSPORT
#

# Use system gzip before explorer gzip
EXP_GZIP=`type gzip 2>;&1 | sed 's/.*is //'`

if echo "${EXP_GZIP}" | egrep -s -e "not found"
then
    EXP_GZIP="${EXP_HOME}/bin/gzip.`uname -p`"
fi

EXP_FNAME=`basename ${EXP_TARGET}`
EXP_FILE="${EXP_FNAME}.tar.gz"

REL=`uname -r | nawk -F. '{ print $2 }'`
case ${REL} in
    3|4|5|6)
        # Pathname fix for tar (5.6 or lower)
        cd ${EXP_TARGET}/..
        MAX=`find ${EXP_FNAME} -type f -print | nawk '{ print length, $0 }' | sort -rn | head -1`
        DIRLEN=`dirname ${MAX} | nawk '{ print length }'`
        PATHLEN=`basename ${MAX} | nawk '{ print length }'`

        #
        # length of directory must be less than 155 and the
        # length of filename must be less than 100 characters
        # for tar to work correctly
        #
        if [ "${DIRLEN}" -ge 155 -o "${PATHLEN}" -ge 100 ]
        then
            cd ${EXP_TARGET}

            # Get list of directories to tar, create exclude file
            DIRS=""
            for dir in *
            do
                [ ! -d "$dir" ] && continue
                DIRS="${DIRS} $dir"
                echo "${EXP_FNAME}/$dir" >;>; ${EXP_TMPDIR}/exclude.${EXP_PID}
            done

            if [ -n "${DIRS}" ]
            then
                # Create tar of DIRS
                tar cf data.tar ${DIRS}
            fi

            # Tar and compress with gzip
            cd ${EXP_TMPDIR}
            tar cfX - ${EXP_TMPDIR}/exclude.${EXP_PID} ${EXP_FNAME} | ${EXP_GZIP} -c >;${EXP_FILE}
            # logfile "${EXP_FILE} created"
            TEXT=`gettext "%s created"`
            TEXT=`printf "${TEXT}" "${EXP_FILE}"`
            logfile "${TEXT}"

            # Remove data.tar from unpacked output
            rm -f ${EXP_TARGET}/data.tar
        else
            # Tar and compress with gzip
            cd ${EXP_TMPDIR}
            tar cf - ${EXP_FNAME} | ${EXP_GZIP} -c >;${EXP_FILE}
            # logfile "${EXP_FILE} created"
            TEXT=`gettext "%s created"`
            TEXT=`printf "${TEXT}" "${EXP_FILE}"`
            logfile "${TEXT}"
        fi
        ;;
    *)
        # Tar and compress with gzip
        cd ${EXP_TMPDIR}
        tar Ecf - ${EXP_FNAME} | ${EXP_GZIP} -c >;${EXP_FILE}
        # logfile "${EXP_FILE} created"
        TEXT=`gettext "%s created"`
        TEXT=`printf "${TEXT}" "${EXP_FILE}"`
        logfile "${TEXT}"
        ;;
esac

# Send the tarball
if [ -n "${EXP_TRANSPORT}" ]
then
    # Make sure EXP_REPLY is available to the transports
    ksh -p ${EXP_LIB}/exp_transport $*
fi

# Clean up
if [ -n "${EXP_STDERR}" ] && [ -s "${EXP_STDERR}" ]
then
    # logfile STDERROR "= = = stderr output from explorer = = ="
    TEXT=`gettext "= = = stderr output from explorer = = ="`
    logfile STDERROR "${TEXT}"
    while read line
    do
        logfile STDERROR "$line"
    done < "${EXP_STDERR}"
fi
test -n "${EXP_STDERR}" && rm -f ${EXP_STDERR}

# Remove old explorer runs if needed
DIR=`dirname ${EXP_TARGET}`
if [ -z "${EXP_KEEP}" ]
then
    # logfile NOTNOISE "removing previous explorers from ${DIR}"
    TEXT=`gettext "removing previous explorers from %s"`
    TEXT=`gettext "removing previous explorers from %s"`
    TEXT=`printf "${TEXT}" "${DIR}"`
    logfile NOTNOISE "${TEXT}"
    cd "${DIR}"

    for i in explorer.`hostid`.`uname -n`-*
    do
        # Keep the most current (directory and tarball)
        test "$i" = "${EXP_ID}"   && continue
        test "$i" = "${EXP_FILE}" && continue

        # Remove old directories
        rm -rf $i
    done
fi

# Log to /var/adm/messages
TEXT=`gettext "Explorer finished"`
logger -p daemon.notice -t explorer "${TEXT}"
logfile NOTNOISE "${TEXT}"
clean 1

exit 0
#
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP