Custom cron interval on openshift cron cartridge

Openshift v1 does not allow custom cron times, cronjobs can only be placed in the folders minutely, hourly, daily, weekly and monthly.

You can use the script below to run a cronjob every 5 minutes. You can vary the timestamp by modifying the +4 parameter. The script must be placed in the minutely folder. Here it will run every minute, and write a timestamp to a temporary file. It will check the creation date of the file, and if it is more than 4 minutes ago the cronjob will run. After that the file will be removed and recreated via the touch command.

The example below will run a PHP cronjob.

#!/bin/bash
if [ ! -f $OPENSHIFT_DATA_DIR/last_run ];
then
    touch $OPENSHIFT_DATA_DIR/last_run
    cd $OPENSHIFT_REPO_DIR;php cronjob.php RememberCron
else
 if [[ $(find $OPENSHIFT_DATA_DIR/last_run -mmin +4) ]]; then #run every 5 mins
   cd $OPENSHIFT_REPO_DIR;php cronjob.php RememberCron
   rm -f $OPENSHIFT_DATA_DIR/last_run
   touch $OPENSHIFT_DATA_DIR/last_run
  fi  
fi