I have a request from user that he want to run a report from server automatically on third Monday every month, I use the following Unix shell script to take care of it.
#RUNDATE=`cal |awk 'NR == 3 { print $2; }'`
#if [ "$RUNDATE" == '' ]; then
NUMBERFIELD=`cal |awk 'NR == 3 { print NF; }'`
if [ $NUMBERFIELD -lt 6 ]; then
RUNDATE=`cal |awk 'NR == 6 { print $2; }'`
else RUNDATE=`cal |awk 'NR == 5 { print $2; }'`
fi
echo $RUNDATE
TODAY=`date +%e`
if [ $TODAY == $RUNDATE ]; then
echo "Today `date +%Y%m%d` is run day!"
else
echo "Today `date +%Y%m%d` is NOT run day!"
echo "run date should be at ${RUNDATE}th, which is the thrid Monday for each month."
exit
fi
#RUNDATE=`cal |awk 'NR == 3 { print $2; }'`
#if [ "$RUNDATE" == '' ]; then
NUMBERFIELD=`cal |awk 'NR == 3 { print NF; }'`
if [ $NUMBERFIELD -lt 6 ]; then
RUNDATE=`cal |awk 'NR == 6 { print $2; }'`
else RUNDATE=`cal |awk 'NR == 5 { print $2; }'`
fi
echo $RUNDATE
TODAY=`date +%e`
if [ $TODAY == $RUNDATE ]; then
echo "Today `date +%Y%m%d` is run day!"
else
echo "Today `date +%Y%m%d` is NOT run day!"
echo "run date should be at ${RUNDATE}th, which is the thrid Monday for each month."
exit
fi
...
sqlplus -s / as sysdba <<- EOF
SET MARKUP HTML ON ENTMAP ON SPOOL ON PREFORMAT OFF
SET ECHO OFF TERM OFF VERIFY OFF FEEDBACK OFF TRIMS OFF PAGESIZE 999
set markup html on
spool filename.html
...
EOF
if [ -f filename.html ]
then
{
uuencode filename.html newname.html|mail -s "subject" email@emailserver.com
}
else
echo "error"
fi
Comments
Post a Comment