2

How can I show all active package repos with zypper?

I need the output for a check script.

I know how to list them all. But I would like to avoid to parse this output with a regex:

foo-work:~ # LANG=C zypper lr
# | Alias                             | Name                          | Enabled | Refresh
--+-----------------------------------+-----------------------------------+---------+--------
1 | openSUSE 12.3 FOO-BAR           | openSUSE 12.3 FOO-BAR           | Yes     | Yes    
2 | openSUSE 12.3 FOO-BAR Test      | openSUSE 12.3 FOO-BAR Test      | Yes     | No     
3 | openSUSE-12.3 Updates (FOO-BAR) | openSUSE-12.3 Updates (FOO-BAR) | Yes     | Yes    
4 | openSUSE-12.3-Non-Oss (FOO-BAR) | openSUSE-12.3-Non-Oss (FOO-BAR) | Yes     | No     
5 | openSUSE-12.3-Oss (FOO-BAR)     | openSUSE-12.3-Oss (FOO-BAR)     | Yes     | No     
guettli
  • 3,591
  • 17
  • 72
  • 123
  • 3
    `man zypper` is helpful, as usual. – Sven Apr 25 '19 at 12:15
  • @Sven I prefer my favorite search engine. If this does not provide an answer, then I will ask a question. This has the big benefit that my team mates (or other people) will find the answer the next time faster (without reading the man page). – guettli Apr 25 '19 at 12:40

2 Answers2

4

Are you looking for the -E, --show-enabled-only flag to only show enabled repositories, or the -e - , --export - to get the listing in the repository definition format that allows for much easier parsing?

zypper lr -E -e - |grep name=
HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • On SuSE 12.3 the `-E` option exists, but does not filter the disabled repos. But I can do this myself. Thank you very much for your answer! – guettli Apr 25 '19 at 12:37
0

This will print only the enabled repositories on SuSE:

zypper lr | awk -F'|' '{gsub(/ /, "", $0); if($4=="Yes") print $2}'

The gsub call is only there to remove the leading and trailing blanks.

duise
  • 1