Super User is a question and answer site for computer enthusiasts and power users. 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

I used the crontab to execute a script, while the script had to do some jobs in the background in this format:

for i in {1..100}
    do_job &

However, the do_job won't be executed by crontab with &, how to fix this problem.My system is Suse.

share|improve this question

migrated from Dec 29 '12 at 17:16

This question came from our site for professional and enthusiast programmers.

Crontab just spawns a shell and has no idea what the shell is running, so probably the problem is elsewhere. Does the script itself even execute? – Thomas Dec 29 '12 at 12:43
cron is not for running things in the background like this. – Ignacio Vazquez-Abrams Dec 29 '12 at 12:43
@lgnacio Is there any solutions? – cheneydeng Dec 29 '12 at 12:44
@Thomas Yes, the script was executed. – cheneydeng Dec 29 '12 at 12:44
Your script contains Bash syntax, does the script file have a valid #!/bin/bash shebang line? Does it fail if you run sh scriptname from the prompt? Cron jobs run with sh unless you explicitly specify Bash. – tripleee Dec 29 '12 at 12:57

You could do something like:

nohup 1> /tmp/script.log 2> /tmp/script.err &

or use screen (deattached)

screen -d -m -S script;

to background processes (see)

share|improve this answer

I think this should work for you:

bash -c "do_job &"
share|improve this answer

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.