-1

In reference to My orginial question, this will be used in my script.

Basically, I run commands to provision CNAME's for domains to validate the domains for TLS. When the command provision-cert test.com.json is run it will output the contents below. Doesn't store them, only prints them in the console.

Determining SubjectAlternateNames for domain test.com
SubjectAlternateNames for domain test.com are:
    test.com
     *.test.com
Requesting Certificate for domain test.com
Certificate for domain test.com has ARN: arn:tmp:tmp:ran-loc- 
1:randomstring:certificate/randomstring

Settings tags on certificate for domain test.com
Retrieving DNS records required for validation for arn:tmp:tmp:ran-loc- 
1:randomstring:certificate/randomstring

Please add these records to DNS to complete validation
     _randomstring.test.com. IN CNAME _randomstring.validations.net.
Certificate needs to complete domain validation

I'm trying to grep the text Please add these records to DNS to complete validation and the line below it _randomstring.test.com. IN CNAME _randomstring.tmp-validations.net. into a .txt file multiples times but I don't want it to overwrite whats already been inserted into the .txt file from previous runs. It will run provision-cert 6 times so essentially I need to to grep each cname after it runs the command provision-cert.

I have tried provision-cert test.com | grep "Please add these records to DNS to complete validation" -A 1 > file.txt but it just freezes.

(I already have my statements in place, I just need to figure out the grep command, and then add it)

Is this possible?

Lex Leach
  • 17
  • 6
  • 1
    What are you stuck with? What have you tried? If the problem is getting lines *after* a match, see https://stackoverflow.com/questions/19274127/how-do-you-grep-a-file-and-get-the-next-5-lines/19274215 – that other guy Sep 21 '18 at 17:44
  • I have tried using `provision-cert test.com | grep "Please add these records to DNS to complete validation" -A 1 > file.txt` but it just freezes on the command. ~Added to question~ – Lex Leach Sep 21 '18 at 18:03
  • Does it output anything at all after you hit enter? – that other guy Sep 21 '18 at 18:24
  • No, well I mean it created the file.txt but its empty. I found the answer though. Thank you for helping. – Lex Leach Sep 21 '18 at 18:26

1 Answers1

1

Found that provision-cert test.com >> file.txt successfully sent the output to a .txt file.

Then adding the command grep "Please add these records to DNS to complete validation" -A 1 file.txt

Answer found here.

Lex Leach
  • 17
  • 6
  • This would not appear to match the specified pattern and find the line below it – that other guy Sep 21 '18 at 18:29
  • I'm glad you found a solution, but this finds information from a file and outputs it to a non-file, which is exactly the opposite of what the question asks for. `provision-cert test.com | grep "Please add these records to DNS to complete validation" -A 1 >> file.txt` really should be working. If you want to debug why it isn't, you can use `provision-cert test.com | tee temporary.txt | grep ... > file` to dump the command's output both before and after the grep and see if maybe it's in a different format than it shows interactively – that other guy Sep 21 '18 at 18:46
  • I see, I will give that a go and see why its not working. – Lex Leach Sep 21 '18 at 18:54