No need for complicated logic and arithmetic. Don't run it around midnight or time changes or the last few days of the month.
#!/bin/bash
for m in {0..14}
do
beg=$(date -d "now - $((m+1)) months" "+%Y-%m-%d")
end=$(date -d "now - $m months" "+%Y-%m-%d")
echo php upgrade_attendance.php refresh_daily_attendance "$beg" "$end"
done
Remove the echo
to make it work
Example:
php upgrade_attendance.php refresh_daily_attendance 2010-08-01 2010-09-01
php upgrade_attendance.php refresh_daily_attendance 2010-07-01 2010-08-01
php upgrade_attendance.php refresh_daily_attendance 2010-06-01 2010-07-01
php upgrade_attendance.php refresh_daily_attendance 2010-05-01 2010-06-01
php upgrade_attendance.php refresh_daily_attendance 2010-04-01 2010-05-01
php upgrade_attendance.php refresh_daily_attendance 2010-03-01 2010-04-01
php upgrade_attendance.php refresh_daily_attendance 2010-02-01 2010-03-01
php upgrade_attendance.php refresh_daily_attendance 2010-01-01 2010-02-01
php upgrade_attendance.php refresh_daily_attendance 2009-12-01 2010-01-01
php upgrade_attendance.php refresh_daily_attendance 2009-11-01 2009-12-01
php upgrade_attendance.php refresh_daily_attendance 2009-10-01 2009-11-01
php upgrade_attendance.php refresh_daily_attendance 2009-09-01 2009-10-01
php upgrade_attendance.php refresh_daily_attendance 2009-08-01 2009-09-01
php upgrade_attendance.php refresh_daily_attendance 2009-07-01 2009-08-01
php upgrade_attendance.php refresh_daily_attendance 2009-06-01 2009-07-01