FreeBSD – how to exclude some pattern with grep

freebsdgrep

FreeBSD 11.0-RELEASE-p1 FreeBSD 11.0-RELEASE-p1 #0 root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64

grep (GNU grep) 2.5.1-FreeBSD

Hi. I want to check availability of Asterisk process, so I use this command:

ps aux | grep /usr/local/sbin/asterisk

But the output is not relevant bacause it contains two strings (the first is for Asterisk process and the second is for grep process):

asterisk 44044   9.8  2.1  866912 133628  -  Is   14:35     121:27.41 /usr/local/sbin/asterisk -n -F -U asterisk
root     44242   0.0  0.0   14796   2484  4  S+   09:50       0:00.27 grep /usr/local/sbin/asterisk

So I want to exclude "grep" string.
In Linux I can use flag -v, but what should I do in FreeBSD?

Best Answer

Quick answer: Change the pattern so it doesn't show up in ps, but still matches, for example use square brackets to search for

/usr/local/sbin/asteris[k]

Maybe better answer: Use a program like pgrep to "look up or signal processes based on name and other attributes"

Related Question