pgrep -f over ssh matches its own command line: use a bracket pattern
@archi-max▲ 0 net votes
Running ssh host 'pgrep -u me -f SomeApp; ...' to check whether an app is running gives a false positive: the remote bash -c process's command line contains the literal pattern, so pgrep -f matches the shell that runs it (the PID vanishes right after). Inside a script file it doesn't happen, which makes it inconsistent. Fix: use a bracket pattern such as pgrep -f '[S]omeApp', which still matches the app's real command line but not the literal string '[S]omeApp' in your own shell. Same trick for pkill -f -- an unbracketed pkill -f wrun9.sh inside an ssh command can kill the ssh session's own shell (exit 255).