Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it a good practice to have a bash script in a VPS with the following skeleton:

while true; do 
    sleep 24h

This is to avoid touching the Cron configuration. Will this cause memory/cpu consumption problems? The script would be loaded at boot time.

UPDATE: Based on the comments, I am asking also how to check if Cron settings are working fine without waiting the time needed for a natural start of the cron job. (I am a very newbie Cron administrator)

Thank you very much for your replies!

share|improve this question
I would say no, it's not good practice. What happens if you reboot or the program is kill -9ed? Even if it's loaded at at boot it still is going to wait 24 hours before doing task. To be mean, I could make a task to reload the system every 22 hours and you'd never get to run your code. :/ You can probably get around this by storing that information in a configuration file and checking if the current date is past the next run date. Though why do that if cron does it already? Cron is there for a reason, so unless there is a very solid reason to avoid using it, use it & save yourself pain. – Robert May 26 '11 at 19:04
Why will it wait for 24hours before doing the job? The script first does the job, then waits for 24hours. – dgraziotin May 26 '11 at 19:09
Perhaps you would be better served to investigate why it doesn't work in Cron? – Magellan May 26 '11 at 19:17
I've just added to the question some details about Cron – dgraziotin May 26 '11 at 19:29

While it would work, this sounds like a bad idea to me. As a system administrator, I expect that periodic executions are done through cron, so it adds complexity to the installation when it is done in a non-standard way.

If the master script was killed for any reason (executed w/o nohup and shell is terminated as one example) the process wouldn't run. Additionally, cron logs all output and the fact that it was executed. You could build all that in to your script, but why re-invent the wheel when cron is already there?

share|improve this answer

I use a configuration like this (though in my case it runs once, sleeps 8 hours, runs again, sleeps 8 hours, runs one last time and dies). Anecdotally I don't think its ever caused any issues. AFAIK having a sleeping process doesn't really do anything resource wise. Any reason you can't touch cron?

share|improve this answer
I don't use Cron because I need to call a Bash script and it doesn't work. I read all the related questions here around and tried everything (setting variables, paths etc.), but still doesn't with Cron. So I thought about a while true bash script – dgraziotin May 26 '11 at 19:07
@dgraziotin - I'd recommend looking into why this bash script isn't working via cron. Speaking in the long term, that's a much better way to go than implementing a "hack" like you described. – EEAA May 26 '11 at 19:11

Your Answer


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.