vincent's Blog

一個無聊的網路雜工的紀錄!!

另一種形式的寫法



#!/usr/bin/sh
####################################
20080524 by vincent
#################################
PATH=$PATH:/usr/openv/volmgr/bin
export PATH
#########################
TO_DAY=`date +%Y%m%d`TODAY=`date +%d`
TOMONTH=`date +%m`
#####################
ALLTAPTLIST=/tmp/log
AGROUP_FILE=/tmp/AGROUPLIST
BGROUP_FILE=/tmp/BGROUPLIST
TMP_FILE=/tmp/tmp_file
OUT_TAPE_FILE=/tmp/out_tapefile
IN_TAPE_FILE=/tmp/in_tapefile
BANK_TAPE_FILE=/tmp/bank_tapefile
MAIL_FILE=/tmp/mail_file
BARCODE_HEAD="TF"
###########################################################
POOLLIST=`vmpool -list_all grep "pool name:" awk '$3 !="None" && $3 !="NetBackup" && $3 !="DataStore" && $3 !="CatalogBackup" && $3 !="changeByScript" {print $3}'`#POOLLIST_CATALOG=`vmpool -list_all grep "pool name:" awk '$3 =="CatalogBackup" {print $3}'`
#############################################################
F_QUERYPOOL(){
for i in $POOLLIST
do
GROUP_COUNT=`vmquery -pn $i grep "media ID:" awk '{printf "%s\n",$3}'wc -l`
x=1
while [ "$x" -le $GROUP_COUNT ]; do
TAPE_LIST=`vmquery -pn $i grep "media ID:" awk '{printf "%s\t", substr($3,3,4)}' cut -f$x`
if [ $x = "1" ];then
TAPE_LIST2=$TAPE_LIST
else
TAPE_LIST3=$TAPE_LIST
fi
x=`echo "$x + 1" bc` done
if [ "$TAPE_LIST2" -lt "$TAPE_LIST3" ];then
echo "DAY$i" " " "$BARCODE_HEAD$TAPE_LIST2" >> $AGROUP_FILE
echo "DAY$i" " " "$BARCODE_HEAD$TAPE_LIST3" >> $BGROUP_FILE
else
echo "DAY$i" " " "$BARCODE_HEAD$TAPE_LIST3" >> $AGROUP_FILE
echo "DAY$i" " " "$BARCODE_HEAD$TAPE_LIST2" >> $BGROUP_FILE
fi
done
}

F_ALL_QUERYPOOL(){
vmquery -pn $1 grep "media ID:" awk '{printf "%s\n",$3}' >> $ALLTAPTLIST
}

F_DAY_RENGE(){
echo "" > $TMP_FILE
if [ $1 = "1" ];then
LAST_MONTH=`/export/home/shell/bin/day $TO_DAY d -7 |awk '{print substr($1,5,2)}'`
LAST_FULLDAY=`/export/home/shell/bin/day $TO_DAY d -7`
elif [ $1 = "2" ];then
LAST_MONTH=`/export/home/shell/bin/day $TO_DAY d +14 | awk '{print substr($1,5,2)}'`
LAST_FULLDAY=`/export/home/shell/bin/day $TO_DAY d +14`
elif [ $1 = "3" ];then
LAST_MONTH=`/export/home/shell/bin/day $TO_DAY d +21 |awk '{print substr($1,5,2)}'`
LAST_FULLDAY=`/export/home/shell/bin/day $TO_DAY d +21`
fi
x=0
while [ "$x" -le "6" ];
do
if [ $1 = "1" ];then
LAST_DAY=`/export/home/shell/bin/day $LAST_FULLDAY d +$x |awk '{print substr($1,7,2)}'`
LAST_MONTH=`/export/home/shell/bin/day $LAST_FULLDAY d +$x |awk '{print substr($1,5,2)}'`
elif [ $1 = "2" ] [ $1 = "3" ];then
LAST_DAY=`/export/home/shell/bin/day $LAST_FULLDAY d -$x |awk '{print substr($1,7,2)}'`
LAST_MONTH=`/export/home/shell/bin/day $LAST_FULLDAY d -$x |awk '{print substr($1,5,2)}'`
fi
if [ $LAST_MONTH = "01" ] ||[ $LAST_MONTH = "03" ] || [ $LAST_MONTH = "05" ]|| [ $LAST_MONTH = "07" ] || [ $LAST_MONTH = "09" ] || [ $LAST_MONTH = "11" ];then
cat $AGROUP_FILE |awk '$1 == DAY {printf "%s\n",$2} ' DAY=DAY$LAST_DAY >> $TMP_FILE elif [ $LAST_MONTH = "02" ] [ $LAST_MONTH = "04" ] [ $LAST_MONTH = "06" ] [ $LAST_MONTH = "08" ] [ $LAST_MONTH = "10" ] [ $LAST_MONTH = "12" ];then
cat $BGROUP_FILE | awk '$1 == DAY {printf "%s\n",$2} ' DAY=DAY$LAST_DAY >> $TMP_FILE
fi
x=`echo "$x + 1" |bc`
done
if [ $1 = "1" ];then
cat $TMP_FILE > $OUT_TAPE_FILE
elif [ $1 = "2" ];then
cat $TMP_FILE > $IN_TAPE_FILE
elif [ $1 = "3" ];then
cat $TMP_FILE > $BANK_TAPE_FILE
fi
}
########################## main start ######################################## inital file #############################
echo "" > $AGROUP_FILE
echo "" > $BGROUP_FILE
echo "" > $OUT_TAPE_FILE
echo "" > $IN_TAPE_FILEe
cho "" > $BANK_TAPE_FILE
echo "" > $TMP_FILE
echo "" > $MAIL_FILE
########################## main start ########################
F_QUERYPOOL
######## tape out the library ############
F_DAY_RENGE 1
######## tape in the library ##########
F_DAY_RENGE 2
######## tape out the BANK #########
F_DAY_RENGE 3
###################################################################################
echo "Tape out the Library" > $MAIL_FILE
echo "-----------------------------------------------------------------" >> $MAIL_FILE
cat $OUT_TAPE_FILE |awk '{printf "%s\n",$1}' sort -n >> $MAIL_FILE
echo "-----------------------------------------------------------------" >> $MAIL_FILE
echo "Tape in the Library" >> $MAIL_FILE
echo "-----------------------------------------------------------------" >> $MAIL_FILE
cat $IN_TAPE_FILE |awk '{printf "%s\n",$1}' sort -n >> $MAIL_FILE
echo "-----------------------------------------------------------------" >> $MAIL_FILE
echo "Tape out the custodian bank " >> $MAIL_FILE
echo "-----------------------------------------------------------------" >> $MAIL_FILE
awk '{printf "%s\n",$1}' $BANK_TAPE_FILE sort -n >> $MAIL_FILE
echo "-----------------------------------------------------------------" >> $MAIL_FILE
mailx -s " Notify: Change Tape " network_log @aaa.com < $MAIL_FILE

0 意見

張貼留言

Categories

追蹤者

Change Language

Your Source