1

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 ?

yarek
  • 11,278
  • 30
  • 120
  • 219
  • 1
    Did you mean `launch` or is there an actual term for `lunch` here that I am unaware of? Serious question. – Compass Oct 30 '14 at 17:40
  • sorry.. It was launch of course :D – yarek Oct 30 '14 at 17:41
  • All kinds of custom solutions come to mind, but have you tried readily available solutions for this kind of thing like `supervisord`? – Wrikken Oct 30 '14 at 17:44
  • sorry, I am not a linux expert. – yarek Oct 30 '14 at 17:46
  • Capture and examine the output of the script to help figure out what is going wrong. Run `bash -x ./script.sh >logfile 2>&1 &` to create a detailed log of what it is doing. In the 'nohup' case, run `nohup bash -x ./script.sh &`, and examine the 'nohup.out' file after the problem has occurred. – pjh Oct 30 '14 at 23:11

1 Answers1

1

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.
Community
  • 1
  • 1
that other guy
  • 116,971
  • 11
  • 170
  • 194
  • killall script.sh : process not found after I logout and login again ! – yarek Oct 30 '14 at 18:05
  • @user300675 If you're getting an error message, please copy-paste the command and entire message rather than typing it from memory. Exact whitespace is important because it points to quoting bugs, exact wording is important because it identifies versions of tools, and entire, unabbreviated command and output can give major clues to issues that just the english message text does not. – that other guy Oct 30 '14 at 18:12
  • root@email1:/var/www# killall script.sh script.sh: no process found – yarek Oct 30 '14 at 18:13
  • @user300675 Add the missing `#!/bin/bash` shebang to your script and try again. – that other guy Oct 30 '14 at 18:17