Once you have that script in your PATH ie either in ~/bin or /usr/local/bin then you can just awk for everything since you're already using it. Here is my example
Code:
ps -eo pid,nice,command | awk '/virtualbox/'
085 0 /usr/lib/virtualbox/VBoxXPCOMIPCD
2099 0 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
2193 0 /usr/lib/virtualbox/VBoxHeadless --comment Apache3 --startvm 847216e3-1d84-4327-9a6a-f1c4050bb792 --vrde config
9299 0 awk /virtualbox/
It prints the awk command as well that is why you needed then grep -v grep, using grep to avoid it
Code:
ps -eo pid,nice,command | grep '[v]irtualbox'
2085 0 /usr/lib/virtualbox/VBoxXPCOMIPCD
2099 0 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
2193 0 /usr/lib/virtualbox/VBoxHeadless --comment Apache3 --startvm 847216e3-1d84-4327-9a6a-f1c4050bb792 --vrde config
However that needs an additional cut command or an awk command to print the second field. No worries since you can do that all in awk.
Code:
ps -eo pid,nice,command | awk '/[v]irtualbox/{print $1}'
ps -eo pid,nice,command | awk '/[v]irtualbox/{print $2}'
In your case that should be something like
Code:
nice=$(ps -eo pid,nice,command | awk '/[b]itcoind/{print $2}')
Code:
pid=$(ps -eo pid,nice,command | awk '/[b]itcoind/{print $1}')
Code:
p2p_nice=$(ps -eo pid,nice,command | awk '/[r]un_p2pool\.py/{ print $2 }')
Code:
p2p_pid=$(ps -eo pid,nice,command | awk '/[r]un_p2pool\.py/{ print $1 }')
The \ before the .py is to make the dot . literal since dot means any character in regrexp. That should be a start, the rest you can adjust as you learn more
.
Bookmarks