Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:32:11+00:00 2026-06-08T17:32:11+00:00

I have a shell script which is executing a php script (worker for beanstalkd).

  • 0

I have a shell script which is executing a php script (worker for beanstalkd).

Here is the script:

#!/bin/bash

if [ $# -eq 0 ]
then
   echo "You need to specify an argument"
   exit 0;
fi

CMD="/var/webserver/user/bin/console $@";
echo "$CMD";
nice $CMD;
ERR=$?

## Possibilities
# 97    - planned pause/restart
# 98    - planned restart
# 99    - planned stop, exit.
# 0     - unplanned restart (as returned by "exit;")
#        - Anything else is also unplanned paused/restart

if [ $ERR -eq 97 ]
then
   # a planned pause, then restart
   echo "97: PLANNED_PAUSE - wait 1";
   sleep 1;
   exec $0 $@;
fi

if [ $ERR -eq 98 ]
then
   # a planned restart - instantly
   echo "98: PLANNED_RESTART";
   exec $0 $@;
fi

if [ $ERR -eq 99 ]
then
   # planned complete exit
   echo "99: PLANNED_SHUTDOWN";
   exit 0;
fi

If I execute the script manually, like this:

[user@host]$ ./workers.sh

It’s working perfectly, I can see the output of my PHP script.
But if I detach the process from the console, like this:

[user@host]$ ./workers.sh &

It’s not working anymore. However I can see the process in the background.

[user@host]$ jobs
[1]+  Stopped                 ./workers.sh email

The Queue jobs server is filling with jobs and none of them are processed until I bring the detached script in the foreground, like this:

[user@host]$ fg

At this moment I see all the job being process by my PHP script. I have no idea why this is happening. Could you help, please?

Thanks, Maxime

EDIT:

I’ve create a shell script to run x workers, I’m sharing it here. Not sure it’s the best way to do it but it’s working well at the moment:

#!/bin/bash

WORKER_PATH="/var/webserver/user/workers.sh"
declare -A Queue
Queue[email]=2
Queue[process-images]=5

for key in "${!Queue[@]}"
do
  echo "Launching ${Queue[$key]} instance(s) of $key Worker..."
  CMD="$WORKER_PATH $key"
  for (( l=1; l<=${Queue[$key]}; l++ ))
    do
        INSTANCE="$CMD $l"
        echo "lnch instance $INSTANCE"
        nice $INSTANCE > /dev/null 2> /dev/null &
    done
done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:32:12+00:00Added an answer on June 8, 2026 at 5:32 pm

    Background processes are not allowed to write to the terminal, which your script tries to do with the echo statements. You just need to redirect standard output to a file when you put it to the background.

    [user@host]$ ./workers.sh > workers.output 2> workers.error &
    

    (I’ve redirected standard error as well, just to be safe.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bash script which calls another bash script, like so: #!/bin/bash echo
Have a shell script that reads the files in a particular directory. #!/bin/bash for
I have written a shell script which executing some of the mysql commands. I
I have a Bash shell script in which I would like to pause execution
I have a shell script which outputs all of the .js and .html files
Hi I have a shell script which should run based on the return of
I have a shell script in which I have to execute two queries (on
I have a unix shell script which test ftp ports of multiple hosts listed
I have a shell script, which is run under a opensuse linux, that starts
I am writing a shell script in which I have to find the last

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.