ENABLE SCHEDS
#!/usr/bin/ksh
clear
usage()
{
echo "\n\tUsage: `basename $0` [ options ... ] "
echo "\tOptions:"
echo "\t\t-h help"
echo "\t\t-a Enable Admin Schedules"
echo "\t\t-c Enable Client Schedules"
echo "\t\t-? usage"
echo ""
exit 1
}
if [[ $# -eq 0 ]]
then
echo No Arguments Selected
usage
fi
help_data(){
echo "\trestart_tsm.ksh"
echo
echo "\tThis script enables schedules on the TSM Server"
echo "\tIf run without any arguments the script will exit without performing any tasks"
echo "\tThe following options are valid"
echo
echo "\t\t-a Enable Admin Schedules"
echo "\t\t-c Enable Client Schedules"
echo
echo "\tAn example below would enable both Client and Admin Schedules"
echo
echo "\t`basename $0` -c -a "
return 0;
}
ADMIN=NO
CLIENT=NO
while getopts "hac" name
do
case $name in
h) help_data
;;
a) ADMIN="YES"
;;
c) CLIENT="YES"
;;
*) usage
;;
esac
done
REP_DIR="/your/report/dir/"
SERVER="yourtsmserver"
TSM_PSWD=/yourpassdir/yourpassfile
date_ext=`date '+%Y%m%d'`
ADMIN_REP="${REP_DIR}adminsched"
CLIENT_REP="${REP_DIR}clientsched"
TSM_CMD=dsmadmc
read ID PASSWORD < ${TSM_PSWD}
tsmCMD="${TSM_CMD} -id=${ID} -pa=${PASSWORD} -comma -dataonly=yes -se=${SERVER}"
rc_chk () {
RC=`echo $?`
if [[ $RC -ne "0" && $RC -ne "11" ]]
then
echo ""
echo "\tExiting... Return Code $RC"
exit $RC;
fi
}
if [[ $CLIENT = YES ]]
then
LASTCLIENT=`ls -tr ${CLIENT_REP}*|tail -1`
if [[ -f $LASTCLIENT ]]
then
ENABLECLIALL=`head -n 1 $LASTCLIENT|awk '{print $1}`
if [[ $ENABLECLIALL != "DATE_EXPIRY" ]]
then
awk -F, '{print "upd sched ",$1,$2" exp=never"}' $LASTCLIENT|tail +2|xargs -I {} $tsmCMD "{}"
rc_chk
else
ENABLEC=`tail +2 $LASTCLIENT`
for enablec in $ENABLEC
do
EXPCHKC=`echo $enablec|awk -F, '{print $3}'`
if [[ -n $EXPCHKC ]]
then
echo $enablec |sed s/,/" "/g|awk '{print $1,$2" exp="$3}'|xargs -I {} $tsmCMD "upd sched {}"
rc_chk
else
echo $enablec |sed s/\,/" "/g|awk '{print $1,$2" exp=never"}'| xargs -I {} $tsmCMD "upd sched {}"
rc_chk
fi
done
fi
else
echo problem with last file
fi
fi
echo
if [[ $ADMIN = YES ]]
then
LASTADMIN=`ls -tr ${ADMIN_REP}*|tail -1`
if [[ -f $LASTADMIN ]]
then
ENABLEADMALL=`head -n 1 $LASTADMIN|awk '{print $1}`
if [[ $ENABLEADMALL != "DATE_EXPIRY" ]]
then
awk -F, '{print "upd sched ",$1," type=admin exp=never"}' $LASTADMIN|tail +2|xargs -I {} $tsmCMD "{}"
rc_chk
else
ENABLEA=`tail +2 $LASTADMIN`
for enablea in $ENABLEA
do
EXPCHKA=`echo $enablea|awk -F, '{print $2}'`
if [[ -n $EXPCHKA ]]
then
echo $enablea |sed s/,/" "/g|awk '{print $1,"type=admin exp="$2}'|xargs -I {} $tsmCMD "upd sched {}"
rc_chk
else
echo $enablea |sed s/\,/" "/g|awk '{print $1,"type=admin exp=never"}'| xargs -I {} $tsmCMD "upd sched {}"
rc_chk
fi
done
fi
else
echo problem with last file
fi
fi