sudo "pkill -f [f]red" Will also work. Because pkill is good about not killing its own pid, but as pointed out doesn't prevent killing the parent shell running pkill where "fred" will also be found.
The above uses a regex of looking for an "f" followed by "red", and since the shell now shows "[f]red" it does not match and won't be killed. On Aug 7, 2013, at 1:16 PM, Francis Fish <[email protected]> wrote: > Hi guys > > Just in case someone reads this again ... cap is running > > sh -c 'pkill -f fred' > > which means the shell will be killed because it matches fred, so it always > returns false. > > See, for example: > > $ pgrep -f nunu > $ sh -c 'pgrep -f nunu' > 16431 > > Which finds the sh with those args > > sh -c 'exec $(pkill nunu || true)' > > Will do what you want because the shell is replaced by the exec command. > > Not sure if this is an issue for cap 3. > > On Sunday, 18 April 2010 10:13:05 UTC+1, Lee Hambley wrote: >> >> Chris, >> >> That's triggered by the posix return code of, in this case pkill or your >> conditional statement. I suggest adding something like a `&& true`; so it >> alwasy returns a `sucess` code. >> >> - Lee >> >> On 17 April 2010 10:52, Christopher Opena <[email protected]> wrote: >>> Hello all, I'm doing some experimentation on using pkill inside of >>> Capistrano to kill multiple processes at once. I'm performing the pkill >>> inside of a bash (sudo "if [cond]; then pkill #{process} fi") conditional. >>> For troubleshooting's sake, I'm making sure the [cond] prints out the >>> output. No problems there, the if [cond] finds and prints out the process >>> and pkill actually does kill the process when it's found, but then >>> Capistrano exits out with a: >>> >>> command finished >>> command "pkill #{process}" failed on #{server_name} >>> >>> Has anyone experienced a problem like this before? >>> >>> I even tried pulling the sudo bash command out of Capistrano and into a >>> bash script and then having Capistrano run the script (sudo >>> "/path/to/script"), and it runs it successfully and I see the task getting >>> killed, but the Cap exists with: >>> >>> command finished >>> command "sudo /path/to/script" failed on #{server_name} >>> >>> Anyone have any ideas? This one is really strange, and I'm a bit stumped. >>> Although it's successful in the end, it makes it hard to place the task in >>> the middle of a long string of tasks because it exits out and doesn't >>> continue :/ >>> >>> Thanks in advance, >>> -Chris. >>> -- >>> * You received this message because you are subscribed to the Google Groups >>> "Capistrano" group. >>> * To post to this group, send email to [email protected] >>> * To unsubscribe from this group, send email to >>> [email protected] For more options, visit this group at >>> http://groups.google.com/group/capistrano?hl=en >> >> -- >> * You received this message because you are subscribed to the Google Groups >> "Capistrano" group. >> * To post to this group, send email to [email protected] >> * To unsubscribe from this group, send email to >> [email protected] For more options, visit this group at >> http://groups.google.com/group/capistrano?hl=en > > -- > -- > * You received this message because you are subscribed to the Google Groups > "Capistrano" group. > * To post to this group, send email to [email protected] > * To unsubscribe from this group, send email to > [email protected] For more options, visit this group at > http://groups.google.com/group/capistrano?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Capistrano" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > -- -- * You received this message because you are subscribed to the Google Groups "Capistrano" group. * To post to this group, send email to [email protected] * To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/capistrano?hl=en --- You received this message because you are subscribed to the Google Groups "Capistrano" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
