⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sms_stats

📁 手机短消息的服务器端和客户端的源代码 是应用于LINUX/UNIX开发环境的
💻
字号:
#!/bin/sh#-----------------------------------------------------------# Program : sms_stats                          Host : zenobe# Author  : Philippe Andersson# Date    : 22/12/98# Version : 1.7# Notice  : (c) Les Ateliers du Heron, 1998 for Scitex Europe, S.A.# Comment : Extract statistics from system logs for SMS subsys.# History :# * 1.0 (22/10/98) : Initial release.# * 1.1 (22/10/98) : Added summary report.# * 1.2 (23/10/98) : Added individual usage count (sms_users)#   and monthly archiving of raw data.# * 1.3 (27/10/98) : Script will run every day, but mail should#   only be sent on weekday. Added code to prevent double inclusion#   in summary file as I did for logfile.# * 1.4 (03/11/98) : Fixed a bug in the TIMESTAMP date format.#   expanded to allow for "at will" re-runs on specified work#   files. Included a modification in the call to sms_users.# * 1.5 (05/11/98) : Added pointer to /var/adm/syslog in work-#   file generation procedure, cause all events >= "warn" will#   be logged there.# * 1.6 (18/12/98) : Adapted to ignore MBC connections after#   installing version 0.32b of the server.# * 1.7 (22/12/98) : Further refined connections count by#   excluding the server's original pid.#-----------------------------------------------------------# Uncomment for debugging# set -x -v# VariablesADMINS="smsmasters"                       # see /etc/aliasesTEMPF="/tmp/messages.copy"WORKF="/tmp/sms_log"SUMMARY="/var/adm/sms_summary"ORIGLOG1="/var/adm/messages"ORIGLOG2="/var/adm/syslog"ARCHDIR="/var/adm/sms_archive"CURARCHF="sms_$(date +%Y%m).log"TODAY=$(date +%Y%m%d)DATESTAMP="$(date +"%b %_d")"DOW=$(date +%a)# Set default value for parametersFILESET=""DATERST="no"#***********************************************************#         CODE BEGINS - GET COMMAND LINE PARAMETERS#***********************************************************# Disable filename generation while parsing parametersset -f#---------------------------------------------Get parameterswhile getopts :f:d: argname; do  case ${argname} in    f) FILESET=${OPTARG}       ;;    d) TODAY=${OPTARG}       DATERST="yes"       ;;    :) echo "sms_stats: missing required value for -${OPTARG} parameter."       exit 1       ;;    ?) echo "sms_stats 1.7 - SMS Server Stats"       echo " "       echo "Usage: sms_stats [-f workfile -d workdate]"       echo " "       echo "where: -f = workfile (opt. - def. automatic)"       echo "       -d = workdate YYYYMMDD (req. iif -f present)"       echo " "       exit 1       ;;  esacdone                                         # while getopts# Handle additional parameters (unused here)shift $((${OPTIND} -1))more_args=${*}# Re-enable filename generationset +f#------------------------------Check for required parameters# no required parameter.#----------------------------------------Validate parametersif [ -n "${FILESET}" ]; then  # check fileset for existence  if [ ! -r ${FILESET} ]; then    echo "sms_stats: the specified workfile (${FILESET}) doesn't exist."    exit 1  fi  # check for -d presence  if [ ${DATERST} != "yes" ]; then    echo "sms_stats: You have to specifiy -d when -f is used."    exit 1  fielse  # error when -d is present  if [ ${DATERST} != "no" ]; then    echo "sms_stats: You can't use -d without -f."    exit 1  fifi#========================================================# Generate workfile if requiredif [ -z "${FILESET}" ]; then  # First take a copy of the "messages" file  if [ -s ${ORIGLOG1} -a -s ${ORIGLOG2} ]; then    cp ${ORIGLOG1} ${TEMPF}    cat ${ORIGLOG2} >> ${TEMPF}  else    exit 1  fi  # Now prune this temp file to keep only SMS info  cat ${TEMPF} | grep "${DATESTAMP}" | grep sms_serv | sort > ${WORKF}  rm -f ${TEMPF}else  WORKF=${FILESET}fi#========================================================# count connections (except those for MBC [mailbox check])nconn=$(cat ${WORKF} | grep -v MBC | awk '{print $5}' | sort | uniq | wc -l)# discount from it the server's entrynconn=$((nconn - 1))# count successfull onesnsucc=$(cat ${WORKF} | grep "message sent OK" | wc -l)succp=$(bc -q << EOT_BCscale=3(${nsucc} / ${nconn}) * 100EOT_BC)# count number of timeout on waiting for free GSM instancentout=$(cat ${WORKF} | grep "(all GSMs busy)" | wc -l)# Log the summary report in tabular format# First check that it's the first time we log this dataif [ -f ${SUMMARY} ]; then  # look for today's date  cat ${SUMMARY} | grep ${TODAY} > /dev/null 2>&1  if [ ${?} -eq 0 ]; then    # prune this data    cat ${SUMMARY} | grep -v ${TODAY} > /var/adm/sms_temp    mv /var/adm/sms_temp ${SUMMARY}  fifi# now append to the fileecho \"$TODAY\",\"$nconn\",\"$nsucc\",\"$succp\",\"$ntout\" >> ${SUMMARY}#========================================================# On weekday only, build mail and send itif [ ${DOW} != "Sat" -a ${DOW} != "Sun" ]; then  mail -s "SMS Server Daily Stats" ${ADMINS} << EOT_MAILStatistics for $(date) on $(hostname).Total connections      : ${nconn}Messages sent OK       : ${nsucc}Percentage successfull : ${succp} %Failed conn. due to timeout waiting for free GSM instance : ${ntout}Usage splitting per individual user :$(/root/scripts/sms_users -f ${WORKF})EOT_MAILfi#========================================================# Archive raw data for further analysisif [ -f ${ARCHDIR}/${CURARCHF} ]; then  # Make sure it's the first time today that we do this  cat ${ARCHDIR}/${CURARCHF} | grep "${DATESTAMP}" > /dev/null  if [ ${?} -eq 0 ]; then    # Prune this data    cat ${ARCHDIR}/${CURARCHF} | grep -v "${DATESTAMP}" > ${ARCHDIR}/temp    mv ${ARCHDIR}/temp ${ARCHDIR}/${CURARCHF}  fi  # Append to it  cat ${WORKF} >> ${ARCHDIR}/${CURARCHF}else  # Zip the previous one(s)  if [ -f ${ARCHDIR}/*.log ]; then    for i in $(ls ${ARCHDIR}/*.log); do      gzip ${ARCHDIR}/${i}    done  fi  # Create a new one  cat ${WORKF} > ${ARCHDIR}/${CURARCHF}fi#========================================================# Clean workfile and exitrm -f ${WORKF}exit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -