Skip to content

Instantly share code, notes, and snippets.

@killerwhile
Created December 27, 2013 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killerwhile/8147087 to your computer and use it in GitHub Desktop.
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.
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