View Single Post
Posts: 89 | Thanked: 194 times | Joined on Feb 2010
#505
Overly complex bit of script:

Code:
sensors_pid=$(ps aux | grep sensors.qcom | grep -v grep | awk '{print $2}')
Could just do
Code:
sensors_pid=$(ps ax | awk '/sensors.qcom$/{print $1}')
And, of course,
Code:
cpu_usage=$(top -b -p $sensors_pid -n1 | grep $sensors_pid | awk '{print $9}')
Could be
Code:
cpu_usage=$(top -b -p $sensors_pid -n1 | awk  -v pid=$sensors_pid '$1 == pid {print $9}')
(edited to get rid of more excess grep's)

Last edited by JohnHughes; 2016-02-23 at 17:48.