About DNS Validation (dns-01) by own script

My own script:

@echo off
cd D:\pythonapp\CertDnsUpate\CertDnsUpate
start python CertDnsUpate.py %*

It will call a python script. It worded well in a cmd command line and renew the dns txt record successfully.(eg. C:"\Program Files\CertifyTheWeb\Scripts\DNS\dnsscript.bat" mydomain _acme-challenge.www.mydomain.com abcdefd)

But it didn’t work in your software.

The log showed:
DNS: (Use Custom Script) :: Warning: Script ran but took too long to exit and was closed.

Not support or something wrong?

Hi, it gets little complicated because when the process runs from the background service it’s running as Local System, the the current user. So you may need to fully qualify the path to your python command (currently it assumes it’s available in the users Path).

I not sure if you need to use start as that will spawn a new CMD process. you should be able to invoke python normally without it.

1 Like

Follow your advice,it worked.

Thank you very much!:grinning::grinning::grinning::+1::+1::+1:

1 Like

Is there any way you be willing to share your python code? I’m having a hard time figuring out how to get the hash txt into the script.

@tdmarchetta I’ll update the scripting docs to add a python example (in answering your question I had to write a script anyway!).

You start with a .bat file which can then forward all the arguments as required to your python script using %* (or you could pass specific arguments if you needed). Note also the fully qualified path to the python exe as your script will run as local system and the path environment variable settings may be different:

REM This script would be called with the parameters <target domain> <record name> <record value> <zone id (optionally)>

REM this example then calls a custom python script forwarding all the arguments

c:\python27\python.exe create_dns_txt_example.py %*

Then in your python script your args are available in the sys.argv list. This example passes that list to a function called main and logs some example stuff (create_dns_txt_example.py logging to dns_create_test.log):

# Example

import sys
import os
import getopt
import logging

# TODO: added module for DNS updates (libcloud etc)

def main(argv):

    # init logging etc
                        filemode='a', level=logging.INFO)

    logging.info("Example Python DNS helper.")

   # TODO: setup your DNS provider (apache libcloud etc)

   # TODO: add/append the txt record

    logging.info("args: " + " ".join(sys.argv))

        "If this script did anything it would create a TXT record called " + sys.argv[2]
        + " with the value " + sys.argv[3]
        + " you could optionally use the domain ("+sys.argv[1]+") "
        + " or zoneId ("+sys.argv[4]+") in your python script")

if __name__ == "__main__":

When the script runs that app will call the .bat file like:

ExampleDNSCreatePython.bat mydomain.com _acme-challenge.mydomain.com ABCD1234 myoptionalZoneId

Which in turn (based on the above example .bat) will call the python script as :

python create_dns_txt_basic.py.bat mydomain.com _acme-challenge.mydomain.com ABCD1234 myoptionalZoneId