Created
December 27, 2013 13:47
-
-
Save killerwhile/8147087 to your computer and use it in GitHub Desktop.
One-liner shell script to purge Cloudera Manager's processes data in /var/run/cloudera-scm-agent/process: delete all but the highest process id.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls -1 /var/run/cloudera-scm-agent/process/ | while read line; do id=$(echo $line | cut -d "-" -f1); process=$(echo $line | sed -e "s/^[0-9]*-//"); echo "$process $id"; done | sort -k1,1r -k2,2nr | while read key value; do if [ "$cur_key" = "$key" ]; then echo -n ",$value"; else if [ "" != "$cur_key" ]; then echo; fi; echo -n "$key:$value"; cur_key=$key; fi; done | grep "." | while read line; do process=$(echo $line | cut -d ":" -f1); ids=$(echo $line | cut -d ":" -f2 | sed -e "s/,/ /g"); first=0; for i in $ids; do if [ "0" = "$first" ]; then first=1; else echo "Deleting /var/run/cloudera-scm-agent/process/${i}-${process}"; rm -fr "/var/run/cloudera-scm-agent/process/${i}-${process}"; fi; done; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment