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.
-
Why does it take two arguments that are the same?Tom Fenech– Tom Fenech2014年11月08日 10:44:36 +00:00Commented Nov 8, 2014 at 10:44
-
No. it can take one date also. I will edit the question.Happy Coder– Happy Coder2014年11月08日 10:46:03 +00:00Commented Nov 8, 2014 at 10:46
1 Answer 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日