Skip to content

Instantly share code, notes, and snippets.

@gustavovelascoh
Created June 20, 2017 14:46
Show Gist options
  • Save gustavovelascoh/2e47fa6fda2d5c47530af44d6f559be0 to your computer and use it in GitHub Desktop.
Save gustavovelascoh/2e47fa6fda2d5c47530af44d6f559be0 to your computer and use it in GitHub Desktop.
resources_monitor
#!/bin/bash
monitors=("monitor_acdc" "batteries_monitor" "monitor_sica")
while :
do
ps_out=$(ps aux)
date=$(date +"%y-%m-%d %H:%M:%S.%N")
for process in "${monitors[@]}"
do
# cmd="ps aux | grep -P \"$process.py\$\" | awk '{print \$2}' >> /var/log/r_mon_err.log 2>&1"
# ps aux | grep -P "$process.py\$" | awk '{print $2, $3, $4}'
# printf '%s\n' "$ps_out" | grep -P "$process.py\$"
# printf '%s\n' "$ps_out" | grep -P "$process.py\$" | awk '{print $2}'
p_pid=$(printf '%s\n' "$ps_out" | grep -P "$process.py\$" | awk '{print $2}' )
# echo "$pid found: $p_pid"
res=$(top -b -p $p_pid -d 0.5 -n 1 | grep $p_pid)
echo "$date $res" >> /var/log/r_mon.log 2>&1
# echo $res
done
sleep 0.5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment