I'm trying to verify the all packages except for a pre-defined list of packages that I know are going to fail for known reasons. This script is going to be run on all Solaris systems within our environment to confirm a system baseline.

I'm open to any technique which will work here, and is possible to put on a single line (Limitation of the tool I'm using for validation).

My initial thought was that I'd take a pkg list, run it through AWK to grab the package name, filter out the packages I don't want, and then run an individual pkg verify on each package remaining individually.

This is the code I've created below:

pkg list | awk 'BEGIN {c=0} $1 == "exclude1" || $1 == "exclude2" { next } { system("pkg verify " $1); c++ } END { if (c == 0) print "none" }'

The problem I'm running into is I'm not seeing any output even though I know there should be a few things that fail the pkg verify.

I thought the system( would capture the output, but I'm relatively new to AWK, and it could be I'm misunderstanding something.

2 Answers 2


On Solaris 11.3, you will want to use nawk rather than awk. nawk ("new awk") is installed by default and should be in your path (/usr/bin/nawk).

The system() function in awk (any implementation) does not return the output of the command, but its exit code. This is ok though, as you probably don't want the actual output from pkg anyway. The pkg command will exit with a non-zero exit code if something went wrong (see the pkg manual).

The following pipeline will take the pkg list output and skip the first line (which is a header), and all lines matching the excluded package names. For the remaining lines of input, it will execute pkg verify through system() with the package name.

If pkg verify returns a non-zero exit status, it will increment a counter. At the end of processing, the counter will be displayed, showing how many verification errors occurred.

pkg list | nawk 'NR > 1 && !/exclude1|exclude2/ { if (system("pkg verify " $1)) { e++ } } END { printf("%d errors\n", e) }'

This is rather inefficient though. It's quicker to get a list of the packages and verify them in one go:

pkg list | nawk 'NR > 1 && !/exclude1|exclude2/ { print $1 }' | ( xargs pkg verify ) || echo "there were errors"

If you have a list of packages to ignore in a file:

pkg list | /usr/xpg4/bin/grep -F -v -f excluded.txt | nawk 'NR > 1 { print }' | ( xargs pkg verify ) || echo "there were errors"

Change your script to use gawk instead o awk.

Simple test:

# pkg list|awk '{system("pkg verify $1")}'

# pkg list|gawk '{system("pkg verify $1")}'
PACKAGE                                                                 STATUS
pkg://solaris/driver/storage/ssd                                         ERROR
  • When I run this on Solaris its like I just ran: pkg verify With no parameters. It doesn't appear to be checking each package individually, which is what I need in order to be able to put a "filter" in the middle and remove some packages from the check.
    – Doug
    Commented May 6, 2015 at 12:58
  • Aka, its running "package verify" on all the packages multiple times.
    – Doug
    Commented May 6, 2015 at 13:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .