I need to run one script which will take one date as an argument. It is configured using cron to run on a daily basis, but I need to run it for a time range now. The issue is that this will fetch all results if it is ran for one day because of the huge size of the table. So is it possible to supply the each date from the start date dynamically from a shell script?

For example: if I need to run update_cron.php from '2013-10-05' then it needs to run

php update_cron.php '2013-10-05'
php update_cron.php '2013-10-06'
php update_cron.php '2013-10-07'

until today (or the end date which is specified). I am very new to shell scripting and so it will be helpful if someone can give an input to this.

1 Answer 1


You can use that code:

for i in $(seq 0 $days);
  php update_cron.php $(date "+%Y-%m-%d" --date="$start_date +$i days")


  • start_date="2014-10-05": Sets the date where you start
  • days=2: sets the number of days you want (note: 2 means 3 days in total, day 0 also counts)
  • for i in $(seq 0 $days);: loops trough $days times
  • php update_cron.php $(...): executes php update_cron.php with the argument
  • $(date "+%Y-%m-%d" --date="$start_date +$i days"): formats the date and estimates the date from $start_date plus $i days

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .