views:

44

answers:

2

I am trying to send the output from the find command to OpenSSL in order to find out when certificates expire.

This finds the files

find . -name \*.pem -type f

This generates the cert info I want

openssl x509 -in certname.pem -noout -enddate

Can I merge these two?

Thanks for your help.

+1  A: 
find . -name \*.pem -type f -execdir openssl x509 -in {} -noout -enddate \;
Matthew Flaschen
Beautiful. I had tried -exec to no avail. Thank you very much.
Starsky
-exec will work too. The only difference is that execdir prevents certain filesystem race conditions (http://www.gnu.org/software/findutils/manual/html_node/find_html/Race-Conditions-with-_002dexec.html). It probably doesn't matter here, but it's a good habit.
Matthew Flaschen
A: 

Just as a general comment on find: your command will run much faster if you take the output of find and pipe it to xargs and let that run the command. The problem being that find spawns a new command for each matching file and that is very slow but if you can pass multiple parameters to the same command (like xargs does) you save all those forks and context switches. It works really well with commands like grep.

Nick
This was my first instinct, but I was unable to get the cert names to print in addition to the enddate output. I wanted both to make a little table out of them.
Starsky