0

I'm trying to loop through all of the repositories on our satellite servers and list the number of rpms in each. I need the repository ID and NAME which I can get from

hammer --csv repository list | grep -v 'Id,Name' | cut -d, -f1,2`

Given ID and NAME, I can get the number of packages and print out:

SUM=$(hammer repository info --id ${ID} | grep Packages | awk '{ print $2 }');
echo "In repository, ${NAME}, there are ${SUM} packages."

I just can't figure out how to put that in a loop. Any suggestions?

2
  • Pipe the output of the command to a while read sum name loop. Commented Nov 10, 2022 at 16:27
  • Or just do it all in awk. Commented Nov 10, 2022 at 16:28

1 Answer 1

1

You could try something like:

hammer --csv repository list | grep -v 'Id,Name' | while IFS=, read -r ID NAME; do
  SUM=$(hammer repository info --id ${ID} | grep Packages | awk '{ print $2 }')
  echo "In repository, ${NAME}, there are ${SUM} packages."
done
Sign up to request clarification or add additional context in comments.

2 Comments

Could the pipe to grep Packages be replaced with a pipe to `awk /Packages/ { print $2 }'?
Yes, it would do the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.