Only at Command Available
When you are a customer DBA at your client's site to do routine db data collection or planned health check tasks, sometimes you have only lower privileges in their hosts, and their security policies cannot be compromised. Then you must find another workaround to make your solution real.
In one case, when you finish a perfect shell script, you may be acknowledged that you have no privilege on crontab to run your script periodically. But the other command at may be there for you to run, see a Solaris example below:
$ echo "/export/home/user/CollectData.sh aug1 aug2" | at 0830pm Nov 30
commands will be executed using /bin/sh
job 8730528700.a at Fri Nov 30 16:30:00 2012
$ atq
Rank Execution Date Owner Job Queue Job Name
1st Nov 30, 2012 16:30 user 8730528700.a a stdin
Please note that, the date format accepted by at may vary in different Unix. And yes, I understand, the workaround may help very little. Let's try another stronger workaround.
Next, our goal is to make an at command list, we can execute the command list to set a whole month at jobs. Here are the steps:
- We are going to edit a shell script file to compose an at command list for setting next month at jobs, this script file will generate an at command list which is executable to run.
- Execute the at command list.
But before editing the composing file, I should remind you about some facts of Solaris:
- Solaris's date function is not GNU date, not BSD date, so don't expect she will generate like "next month", "yesterday" for you.
- The at command accepted time format is a C type format. It's very tricky to get the next of month in locale abbreviated form. So, you can see the composing file is a little longer than expected:
Auto Scheduled Script
$ vi compose_at_commands
#!/bin/bash
WORKING_DIR=/export/home/user/atjobs
EXECFILE=execute_at_jobs.sh
YEAR=`date +%Y`
MON1=`date +%b`
MON2=`date +%m`
for var in `echo "Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"`
do
if [ $FOUND = TRUE ] ;
then
break
fi
if [ $MON1 = $var ] ;
then
if [ -z $FOUND ] ;
then
MON2=1
YEAR=`echo $YEAR 1 | awk '{printf $1+$2}'`
else
MON2=`echo $MON2 1 | awk '{printf $1+$2}'`
fi
FOUND=TRUE
else
FOUND=FALSE
fi
done
cat /dev/null > $WORKING_DIR/$EXECFILE
chmod u+x $WORKING_DIR/$EXECFILE
for day in `cal $MON2 $YEAR | sed '1,2d'`
do
ATCMD="echo "/export/home/user/CollectData.sh aug1 aug2" | at 0830pm $var $day"
echo $ATCMD >> $WORKING_DIR/$EXECFILE
# $WORKING_DIR/$EXECFILE
done
Note that, the last two line is commented out for you as an option to review the command file before execution, or you can execute immediate.
The generated executable file is like this:
...
echo "/export/home/user/CollectData.sh aug1 aug2" | at 0830pm Nov 28
echo "/export/home/user/CollectData.sh aug1 aug2" | at 0830pm Nov 29
echo "/export/home/user/CollectData.sh aug1 aug2" | at 0830pm Nov 30
I hope the script help you a lot, if not, don't be too picky, it's a workaround though.