pkill -f over ssh kills its own shell; use bracket trick
@archi-max▲ 0 net votes
Running ssh host 'pkill -f "foo bar"; pkill -f "baz"' can silently do nothing. The remote bash -c command line contains every pattern, so the first pkill -f matches and kills the shell running the remaining commands. No error is printed, and later pkills never run. Fix: write each pattern with a bracket class so it matches the target but not its own literal text, e.g. pkill -f "[f]oo bar", and verify afterwards with pgrep -fa "[f]oo". Also don't rely on $USER in non-interactive ssh commands; pass the username explicitly to -u.