
#!/bin/ksh
# Collect and send monthly kpi data asml filers 
# Wim Roelofs
#set -x
PATH=$PATH:/usr/bin; export PATH
#
KPILOC=/users/nldsm01/scripts/data
TMPLOC=/users/nldsm01/scripts/tmp
KPI_1=daily_pbs_summary.csw
KPI_2=uptime_hwnaf01_daily.log
KPI_3=uptime_nlnaf02_daily.log
#RECIPIENT="koos.horvers@atosorigin.com" # SDM
RECIPIENT=$1 # email address as parameter

# script runs in cron 1st day of month, reporting must be done
# over previous month
# date format in datafiles must be YYYY-MM-DD
str=`date +%Y-%m`
year=`echo $str |cut -d- -f1`
month=`echo $str| cut -d- -f2`

case $month in
 01) p_month=12; let year=$year-1;;
 10|11|12) let p_month=$month-1;;
 02|03|04|05|06|07|08|09) digit=`echo $month |tr -d 0`; let p_month=$digit-1;;
esac 

if [ $p_month -gt 9 ]; then
  str="$year-$p_month"
else
  str=$year-"0$p_month" # month as MM
fi

# Send data to Service Delivery Manager

# send KPI pbs succeeded/failed
cat ${KPILOC}/${KPI_1} |head -1 > ${TMPLOC}/asml_pbs_success_kpi_${str}.csv
grep $str ${KPILOC}/${KPI_1} >> ${TMPLOC}/asml_pbs_success_kpi_${str}.csv
uuencode ${TMPLOC}/asml_pbs_success_kpi_${str}.csv asml_pbs_success_kpi_${str}.csv| mailx -s "asml pbs kpi data" ${RECIPIENT}

# send KPI pbs uptime
cat ${KPILOC}/${KPI_2} |head -1 > ${TMPLOC}/asml_pbs_hwnaf01_uptime_kpi_${str}.csv
grep $str ${KPILOC}/${KPI_2} >> ${TMPLOC}/asml_pbs_hwnaf01_uptime_kpi_${str}.csv
uuencode ${TMPLOC}/asml_pbs_hwnaf01_uptime_kpi_${str}.csv asml_pbs_hwnaf01_uptime_kpi_${str}.csv | mailx -s "asml pbs kpi data" ${RECIPIENT}

cat ${KPILOC}/${KPI_3} |head -1 > ${TMPLOC}/asml_pbs_nlnaf02_uptime_kpi_${str}.csv
grep $str ${KPILOC}/${KPI_3} >> ${TMPLOC}/asml_pbs_nlnaf02_uptime_kpi_${str}.csv
uuencode ${TMPLOC}/asml_pbs_nlnaf02_uptime_kpi_${str}.csv asml_pbs_nlnaf02_uptime_kpi_${str}.csv | mailx -s "asml pbs kpi data" ${RECIPIENT}

