Skip to content

Instantly share code, notes, and snippets.

@philz
Created December 27, 2013 16:58
Show Gist options
  • Select an option

  • Save philz/8149617 to your computer and use it in GitHub Desktop.

Select an option

Save philz/8149617 to your computer and use it in GitHub Desktop.
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}"
echo 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