Question: I'm trying to run this script every 5 minutes. It seems the only way to run CRON jobs on OpenShift is to use their CRON plugin. And the CRON plugin only allows for minutely, hourly, and daily scripts (by placing the script in the corresponding folder).

I am trying to run this script every 5 minutes:

```
#!/bin/bash
php /var/lib/openshift/53434c795973ca1ddc000668/app-root/runtime/repo/scheduled.php > /dev/null 2>&1

```

But right now it runs every minute (because it's placed in the minutely folder).

How can I re-write it so that it runs every 5 minutes?

Answer: 
Modify the script so it checks the current time, and bails out if it's not a multiple of 5 minutes.

Something like this:

```
#!/bin/bash

minute=$(date +%M)
if [[ $minute =~ [05]$ ]]; then
    php ...
fi

```

The right operand of the `=~` operator is a regular expression; the above matches if the current minute ends in `0` or `5`. Several other approaches are possible:

```
if [[ $minute =~ .[05] ]]; then

```

(check for any character followed by a `0` or `5`; `$minute` is always exactly 2 characters).

(User theshadowmonkey suggests in a comment:

```
if [ $(($minute % 5)) -eq 0 ]; then

```

which checks arithmetically whether `$minute` is a multiple of 5, but there's a problem with that. In the expression in a `$(( ... ))` expression, constants with leading zeros are treated as octal; if it's currently 8 or 9 minutes after the hour, the constant `08` or `09` is an error. You could work around this with `sed`, but it's probably not worthwhile given that there are other solutions.)
You can make use of **minutely** cron job available. The jobs are run at a specified frequency and you can instrument your job to inspect the date and/or time when your job runs.

Here is an example for running a job every 5 minutes. Place the below code snippet in an executable file at path `.openshift/cron/minutely/awesome_job` and give proper permissions `chmod +x awesome_job` then add it to your application repository, commit and push.

The snippet

```
#!/bin/bash
if [ ! -f $OPENSHIFT_DATA_DIR/last_run ]; then
  touch $OPENSHIFT_DATA_DIR/last_run
fi
if [[ $(find $OPENSHIFT_DATA_DIR/last_run -mmin +4) ]]; then #run every 5 mins
  rm -f $OPENSHIFT_DATA_DIR/last_run
  touch $OPENSHIFT_DATA_DIR/last_run
  # The 'awesome_command(s)' that you want to run every 5 minutes
fi

```

**Explanation:**

* This snippet actually creates an empty file named 'last\_run' just to
note down the last run status and then starts your job.
* The next minute, your 'awesome\_job' will be executed and now it tries to find file 'last\_run' modified in last 4 minutes. But your
file 'last\_run' was created just a minute ago and hence the condition fails and exits. This continues.
* At fifth minute, while finding (with `-mmin +4`), your 'last\_run' will be shown and now, the file 'last\_run' will be deleted and recreated and your awesome command(s) will be executed.

Source (Official Docs): <https://developers.openshift.com/managing-your-applications/background-jobs.html#_execution_timing>