The jerk in this scenario is the linux command ‘ps’. I was using it recently in a script that checks to make sure a certain process is running. Whenever I would run the command directly, I would get the desired response, a 1, indicating that the process was found. However, when I would run my script, I would always get a 0.
Here is the command in question: ps aux | grep -v grep | grep -c myprocess
While troubleshooting the issue, I had my script email me the entire output of ‘ps aux’ and you know what? That shit was truncated! WTF!? I understand it being truncated on the command line, depending on the size of your terminal, but why in a script? Regardless, I now knew why it was returning 0. The particular process name that I was looking for wasn’t part of the truncated output. I googled around a bit and found the answer:
ps auxww | grep -v grep | grep -c myprocess
From the man page:
[note color=”#DDD”]wWide output. Use this option twice for unlimited width.[/note]