0

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.

asked Nov 8, 2014 at 10:36
2
  • Why does it take two arguments that are the same? Commented Nov 8, 2014 at 10:44
  • No. it can take one date also. I will edit the question. Commented Nov 8, 2014 at 10:46

1 Answer 1

1

This function should get you started

iterdate() {
 cur="1ドル"
 end="2ドル"
 while [ $cur != $end ] 
 do
 echo php update_cron.php $cur 
 cur=$(date -d "$cur + 1 day" +%Y-%m-%d)
 done
 }

The you can use it like this

$ iterdate 2013年10月05日 2013年10月08日
php update_cron.php 2013年10月05日
php update_cron.php 2013年10月06日
php update_cron.php 2013年10月07日

Just remove the echo in it to make it actually run the php update command. Note that if you need to run that in a cron job, you might find it easier to make a script of it rather than a function. Then copy the following in a text file and make it executable

#!/bin/bash
cur="1ドル"
end="2ドル"
while [ $cur != $end ] 
do
 echo php update_cron.php $cur 
 cur=$(date -d "$cur + 1 day" +%Y-%m-%d)
done

And then

$ /path/to/iterdate.sh 2013年10月05日 2013年10月08日
php update_cron.php 2013年10月05日
php update_cron.php 2013年10月06日
php update_cron.php 2013年10月07日
answered Nov 8, 2014 at 11:05
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.