Re: Pass Date variable in cron job
Posted in 1995
tangh@cc.memphis.edu wrote:
>Hello, everyone. I need to run a job everyday automatically. In the SQL
>procedure, I have date = "07/11/95" to run for july 11 report. I have been
>trying to pass the data to the SQL program and let it run automatically . I
>created a CRON job, and couldn't find right sytax to pass the date variable.
>Could some one help with this question. I am using INFORMIX online, dbaccess
>to run the sql program. Thanks. Tina.
I do something similar with a shell script. Use something like this:
#!/bin/ksh
#--- sample.ksh - Sample SQL access through shell script.
CURR_DATE=$(date +%D)
dbaccess mydatabase - <<!END_OF_DB_CMDS >> /tmp/sql_log 2>&1
OUTPUT TO "flatfile.txt"
SELECT * FROM sometable
where date = ${CURR_DATE};
!END_OF_DB_CMDS
#EOF
The crontab entry would look something like this:
## Layout of the Crontab File.
## min hr dom mo dow commands
3 3 * * 0 . ./.informix; ./lbin/sample.ksh >/dev/null 2>&1
Note: Source the ".informix" file first to set DB environment.
Hope that helps!
--
Karl Bishop <kfb@triad.com>
3055 Triad Drive Voice#: 510.227.5715
Livermore, CA 94550 FAX#: 510.227.5759
~
~