Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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

share|improve this question
    
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' Sep 13 '11 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. –  espekia Sep 13 '11 at 20:56
add comment

1 Answer

up vote 3 down vote accepted

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)

Regards

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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