PyEZ - Cron Job to connect to 8 routers and save the running config to 8 local files at a specific time stamp

167 views Asked by At

I am a starter to PyEZ. Can I write a cron job in PyEZ which will connect to 8 routers and fetch the running Config on device and save to 8 different files at a particular timestamp. Could you help me achieve the same.

I have already written a PyEZ code which will write the Base config to my local file.

Loading the config files to local file

from jnpr.junos import Device from lxml import etree dev = Device(host='hostname',port='22',user='root', password='sitlab123!' ) dev.open()class Create_Config():

def __init__(self):

    cnf = dev.rpc.get_config() ####Get Config as Str
            with open('myfile.txt', "w") as text_file:

            text_file.write(etree.tostring(cnf))

            text_file.close()

#####Return Configuration

def get_conf(self):

    return dev.cli("show configuration")
1

There are 1 answers

0
Vijay Shetty On

You can use python-crontab module along with PyEZ module.

Python-crontab

To create a new cron job is as follows:

from crontab import CronTab
#init cron
cron   = CronTab()

#add new cron job
job  = cron.new(command='/usr/bin/echo')

#job settings
job.hour.every(4)