yarek
yarek

Reputation: 12034

why nohup does not launch my script?

Here is my script.sh

for ((i=1; i<=400000; i++))
do
   echo "loop $i"
   echo 
   numberps=`ps -ef | grep php | wc -l`;
   echo $numberps
   if [ $numberps -lt 110 ]
   then
   php5 script.php &
   sleep 0.25
   else
     echo too much process
    sleep 0.5
fi
done

When I launch it with:

./script.sh > /dev/null 2>/dev/null &

that works except when I logout from SSH and login again, I cannot stop the script with kill%1 and jobs -l is empty

When I try to launch it with

nohup ./script.sh &

It just ouputs

nohup: ignoring input and appending output to `nohup.out'

but no php5 are running: nohup has no effect at all

I have 2 aleternatives to solve my problem:

1) ./script.sh > /dev/null 2>/dev/null & If I logout from SSH and login again, How can I delete this job ?

or 2) How to make nohup run correctly ?

Any idea ?

Upvotes: 1

Views: 849

Answers (1)

that other guy
that other guy

Reputation: 123410

nohup is not supposed to allow you to use jobs -l or kill %1 to kill jobs after logging out and in again.

Instead, you can

  • Run the script in the foreground in a GNU Screen or tmux session, which lets you log out, log in, reattach and continue the same session.
  • killall script.sh to kill all running instances of script.sh running on the server.

Upvotes: 1

Related Questions