pacs

#!/bin/sh

if [ $# -eq 0 ]; then
echo "Usage: pacs [options]"
echo "          -d: only data"
echo "          -h: in last hours"
echo "          -t: old day 2013-11-17"
echo "          -c: only company mn="
echo "e.g:"
echo " pacs "
echo " pacs -dh3 -c52072210202501"
        echo " pacs -t2013-11-16 -c52072210202501"
fi

echo ""

acs_pid=`ps -ef|grep bear-access-server|grep -v grep|awk '{print $2}'`
if [ -n $acs_pid ]; then
echo "bear-access-server is running. pid: $acs_pid"
else
echo "Warnig: bear-access-server process does not start !!"
fi

LOG_FILE=/root/logs/bear-standalone-server.log
TIME_FMT="+%Y-%m-%d"
STIME=''
ETIME=''
MN=''
H=1
DAY=''
DATA_ONLY=''
echo ""
while getopts "h:c:t:d" arg
do
case $arg in
c) MN=$OPTARG ;;
h) H=$OPTARG ;;
t) DAY=$OPTARG ;;
d) DATA_ONLY=$OPTARG ;;
?) echo "unkonw args"
esac
done

SHOW=""
if [ 'x'$DAY == 'x' ]; then
SHOW="Today"
if [ 'x'$H != 'x' -a -n $H ]; then
SHOW="$SHOW in $H hours"
TIME_FMT=${TIME_FMT}" %H:%M:%S"
ETIME=`date "$TIME_FMT"`
STIME=`date "$TIME_FMT" -d "-$H hours"`
fi
else
SHOW="Date $DAY"
LOG_FILE=${LOG_FILE}"."${DAY}
STIME=$DAY" 00:00:00"
ETIME=$DAY" 23:59:59"
fi
SHOW="$SHOW stime=$STIME etime=$ETIME from: $LOG_FILE"

#ACS_NUM=`grep "$LOG_TIME" $LOG_FILE | grep "MN=$MN" |grep "I2DC"|grep -c "DataTime"`
#echo "The number of heartbeats hours: $ACS_NUM "
#echo "Last $NUM records: "
#grep "$LOG_TIME" $LOG_FILE | grep "MN=$MN" |grep "I2DC"|grep "DataTime"|head -n $NUM \
#|awk '{print $1,$2,$7,$8}'

MY_CMD="grep I2DC $LOG_FILE |grep MN=$MN";
if [ "x"$DATA_ONLY == "x" ]; then
MY_CMD="${MY_CMD}|grep DataTime"
fi

MY_CMD="$MY_CMD|awk '{print \$1\" \"\$2\"@@\"\$8}'"
COUNT_CMD=$MY_CMD

if [ "x"$MN == "x" ]; then
SHOW="Show All Company on $SHOW"
MY_CMD="$MY_CMD|awk 'BEGIN{FS=\"@@\";stime=\"$STIME\";etime=\"$ETIME\"} \$1 >= stime && \$1 <= etime {print \$1,\$2}'"
MY_CMD="${MY_CMD}|awk 'BEGIN{FS=\";\"}{print \$3}'|awk 'BEGIN{FS=\"=\"}{print \$2}' |sort |uniq -c"
COUNT_CMD="${MY_CMD}|awk '{print \$2}'|sort|uniq -c|wc -l"
MY_CMD="${MY_CMD}|awk 'BEGIN{print \"COMPANY_MN\tCOUNT\"}{print \$2\"\t\"\$1}'"
else
SHOW="Show Company(MN=$MN) on $SHOW"
MY_CMD="${MY_CMD}|awk 'BEGIN{FS=\"@@\";stime=\"$STIME\";etime=\"$ETIME\";} \$1 >= stime && \$1 <= etime {print \$1,\$2}'"
fi

echo "${SHOW}"
echo ""
echo "The number of companies have access to bear-access-server(ACS): `eval $COUNT_CMD`"
echo ""
#echo $MY_CMD
eval $MY_CMD
#grep "I2DC" $LOG_FILE | grep "MN=$MN" |grep "DataTime"|awk '{print $1" "$2"@@"$8}'|eval $MY_CMD
#|awk '{print $1" "$2"@@"$8}'|eval $MY_CMD |awk 'BEGIN{FS=";"}{print $3}'|awk 'BEGIN{FS="="}{print $2}' |sort |uniq -c


echo ""

你可能感兴趣的:(pacs)