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.

  • 1
    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, 2012 at 12:43
  • 1
    cron is not for running things in the background like this. Dec 29, 2012 at 12:43
  • @lgnacio Is there any solutions?
    – rpbear
    Dec 29, 2012 at 12:44
  • @Thomas Yes, the script was executed.
    – rpbear
    Dec 29, 2012 at 12:44
  • 3
    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, 2012 at 12:57

2 Answers 2


You could do something like:

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

or use screen (deattached)

screen -d -m -S script script.sh;

to background processes (see)


I think this should work for you:

bash -c "do_job &"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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