Pass system date and sysdate-7 in script through crontab

Hi ,

I have to schedule one job in crontab, but with two parameters.

  1. Sysdate in YYYYMMDD format
  2. Sysdate - 7 in YYYYMMDD format

Please suggest how to do that.

Thanks in advance.

Have a read of two things:-

  • The manual page for the date command
  • Search this forum for date and you will find lots of threads to do what you want.

You may need use cron to call a wrapper script that works these out and then calls the real script you want, e.g.:-

$ crontab -l
00 23 * * * /my_home/wrapper_script
$ cat wrapper_script
#!/bin/ksh

d1=20140603          # Need to get this from the date command
d2=20140527          # Need to calculate this from the date command

/usr/local/scripts/main_script $d1 $d2

I hope that this helps, but in any case:-

  • What have you tried so far?
  • What errors/output are you getting?
  • What OS and version are you using (some have more options on the date command)

Robin