I'm running a python script on my VPS every day with cron. It only has 768mb ram, and when I run the script manually I often get memory errors from python. However, I usually can just try a couple more times and it works.

Obviously, cron only runs it once, and this means that most days the task doesn't happen. Is there a way to monitor python's output and tell cron to keep running until it runs without errors?

Obviously i would put a limit of say 5 runs on, so it doesn't go forever and crash my server.

Additionally, are there some command line Linux tools to free up memory before it runs, to increase chances of it working? I'm running Ubuntu Server 11.04

  • Isn't the actual solution here to upgrade your server? Whatever you're doing has presumably built up to this point, not always been this way. It's going to reach another point where this little trick doesn't work anymore.
    – Su'
    Commented Sep 13, 2011 at 20:49
  • No, it's been the same situation from the beginning, and it always works after a few tries, just rarely on the first. Upgrading would be ideal, but nothing else I do needs more ram, so it would be a waste of money for this one thing. It's not an essential process.
    – lavelle
    Commented Sep 13, 2011 at 20:56

1 Answer 1


Cron is only run "once" at specific time or "every" minutes/hours. It doesn't check the return code. But a wrapper script CAN check the output.

I suggest that you launch a "wrapper" to your script, then, the script will check itself for the presence of a file "/tmp/runcomplete", check for the run counter in another file, well, you get the idea.

From my opinion :

  • Fix your app memory problem, programs should be 1 or 0, not try it may work
  • Take another server or consider cloud computing with on demand instances
  • Look at the script memory usage and tweak your vm memory kernel settings (sysctl.conf)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.