Gregor Stopar Gregor Stopar - 6 months ago 63
MySQL Question

CRON job on OPENSHIFT PaaS

So I would like to periodically run a script in my application that Im running on openshift PaaS. I would like to periodically delete some entries from my database.
I've installed CRON cartridge and I have put a bash script which looks like this:

#!/bin/bash

php /erase.php


in .openshift/cron/minutely which should run a script every minute. Ive put erase.php in the root folder of my git repository, so I think that there are no errors in code above.
My erase.php looks like this:

<?php
try {
$bdd = new PDO('mysql:host=127.*.***.*:****;dbname=track', '****', '*****');
} catch(Exception $e) {
exit('Unable to connect to db.');
}

$sql = "DELETE FROM table";
$q = $bdd->prepare($sql);
$q->execute();

?>


As far as I can see there can't be anything wrong with the above code. Is there something else that I'm missing?

EDIT:
Problem is solved, in bash script the path has to be like this:
php $OPENSHIFT_REPO_DIR/erase.php

Answer

The absolute path in the bash script does not seem to be correct. Your repo directory is not the root. You can use environment variables to specify the absolute path to your bash script. As the erase.php is in root of your repo, that would be:

php $OPENSHIFT_REPO_DIR/erase.php

You should see an error log for the minutely cron job in ~/app-root/logs/cron_minutely.log, after sshing into your app, should you need to troubleshoot the job itself.

If the cron job does not seem to be running at all, make sure you have added the Cron add-on cartridge to your app and that your bash script file is executable, as suggested in the comments.

Comments