I work for a webhost as a front level tech and often we need to install a SSL for a customer. I'm on a Mac now but am familiar with Linux as well.

What I'm looking to do would be to take the zipped file, download it to my mac and then run the command to both unzip it and cat at one pop. Thus eliminating the tedious process of unzip file.zip and then copy each file, one at a time to run cat.

I'm lame when it comes to writing a script and have played around with multiple commands, none that worked out.

  • 1
    cat just displays the content of a file (or can be used to append it to another one). Can you list the steps required (those you do manually) in more detail, ideally exactly the way they are executed in Terminal? – nohillside Nov 11 '15 at 22:17
  • 1
    Ah, and please do not post the same question on different SE sites at once. If you don't get (good) answers questions can always be migrated to a better-suites site. In your case, improving the question is probably more important before we consider moving it. – nohillside Nov 12 '15 at 9:50
  • Typically I ls to locate the zip file in the Downloads folder. Next type unzip filename.zip to extricate the contents, usually two files. After that I type cat and paste each file name to be able to load the contents of the two files at once for copying to the server. Sorry about the double posting. Thought more exposure may help. – sdw215 Nov 12 '15 at 22:51
  • What I still don't understand: Why only cat/display the file and not use the shell script to put it directly onto the server? – nohillside Nov 14 '15 at 7:42
  • @ patrix I don't have ssh access to the root of the server to install it. That's the only glitch but with the script this far along it wouldn't take much to finish it of to gain ssh access like you describe. – sdw215 Nov 15 '15 at 20:49

So I've done some testing, and it seems that gzcat (and event zcat) on OS X only work for gzipped files, and not files using standard zip compression. That being said, I believe this is what you are looking for:

"sub.domain.tld.ssl.zip" contains 2 files:

  • "sub.domain.tld.crt" (SSL certificate)
  • "sub.domain.tld.key" (RSA private key)

In order to print all files to STDOUT, you would use unzip -p

To "cat" the certificate, you could use the following command:

unzip -p sub.domain.tld.ssl.zip | sed -n '/CERT/,/CERT/p'

To "cat" the private key, you could use the following command:

unzip -p sub.domain.tld.ssl.zip | sed -n '/KEY/,/KEY/p'

Afterwards, of which you could do what you wish, such as create a little script or function:

unzip -p "$1" | sed -n '/CERT/,/CERT/p' > "/etc/ssl/Certs/${2}.crt"
unzip -p "$1" | sed -n '/KEY/,/KEY/p' > "/etc/ssl/Private/${2}.key"

The above script would take 2 arguments (which should ideally be enclosed in quotes):

  1. File name of zip file
  2. Naming convention of cert/key files

If the name of the script was sslinstazip.sh, you would run it like so:

./sslinstazip.sh "sub.domain.tld.ssl.zip" "sub.domain.tld"

There are obviously many ways you can modify this to fit your own personal needs, but in this case, unzip is actually your friend.


I actually found a way to do this with the help of a friend at work tonight.

#Script to run unzip and cat in one command

zipinfo -1 $1 > $1.txt;
unzip $1;
for i in $(cat $1.txt); do echo "File : $i >>" && cat $i; done

Saved it in TextWrangler as uzipcat.sh and ran chmod u+x

To run it I type ./uzipcat.sh sslfilename.zip and it extracts it plus prints the contents.

Thanks for the interest and suggestions!


Skip the unzip and use gzcat directly. I'm not sure what "install a SSL" involves, but if you ask a follow on question with that detail, link it in a comment here and I'll have a look.

Also, making a short shell script might help you pick apart the requirements of your automation if Automator isn't powerful enough for your needs.

  • gzcat is not the same on Unix-based operating systems. zcat may be required instead. However, there are multiple ways of going about doing this. As you said, just figure out the commands you need to do what you need to do, and then voila, shell script. You could also just use it as a function in your .bash_profile, because it's probably not going to be very many commands. – rubynorails Nov 11 '15 at 23:49
  • 1
    @rubynorails Good info - it works decently well on most OS X so I figured it might be a good place for the OP to start if they're not good with pipes and redirection yet. – bmike Nov 12 '15 at 2:35
  • See my answer. It appears we were both wrong! – rubynorails Nov 12 '15 at 4:15

You must log in to answer this question.

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