我真的是太懶了,原本這隻script在crontab中執行有些小問題,我都一直偷懶沒除錯....一直到現在。真是......
其實這隻程式的小問題,是我忘了本質(沒設環境變數),真是要自我檢討一下。
#!/sbin/sh
####################################
20080524 by vincent
#################################
PATH=$PATH:/usr/openv/volmgr/bin
export PATH
################################
TO_DAY=`date +%Y%m%d`
TODAY=`date +%d`
TOMONTH=`date +%m`
#####################
TEMP_PATH=/export/home/shell/TAPE/TEMP
ALLTAPTLIST=$TEMP_PATH/log
AGROUP_FILE=$TEMP_PATH/AGROUPLIST
BGROUP_FILE=$TEMP_PATH/BGROUP
LISTTMP_FILE=$TEMP_PATH/tmp_file
OUT_TAPE_FILE=$TEMP_PATH/out_tapefile
IN_TAPE_FILE=$TEMP_PATH/in_tapefile
BANK_TAPE_FILE=$TEMP_PATH/bank_tapefile
MAIL_FILE=$TEMP_PATH/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}'`
#############################################################
echo "" > $AGROUP_FILE
echo "" > $BGROUP_FILE
echo "" > $OUT_TAPE_FILE
echo "" > $IN_TAPE_FILE
echo "" > $BANK_TAPE_FILE
echo "" > $TMP_FILE
echo "" > $MAIL_FILE
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
for xx in 1 2 3
do
echo "" > $TMP_FILE if [ $xx = "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 [ $xx = "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 [ $xx = "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 [ $xx = "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 [ $xx = "2" ] [ $xx = "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 [ $xx = "1" ];then
cat $TMP_FILE >> $OUT_TAPE_FILE
elif [ $xx = "2" ];then
cat $TMP_FILE >> $IN_TAPE_FILE
elif [ $xx = "3" ];then
cat $TMP_FILE >> $BANK_TAPE_FILE
fi
done
###################################################################################
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
cat $BANK_TAPE_FILE awk '{printf "%s\n",$1}' sort -n >> $MAIL_FILE
echo "-----------------------------------------------------------------" >> $MAIL_FILE
mailx -s " Notify: Change Tape " network_log@AAA.com < $MAIL_FILE
張貼留言