Thursday, 21 February 2019

compare two different files line by line in Python

import difflib
from difflib import HtmlDiff


with open('show_run_SW-VSS_2019-02-05.txt') as f1:
    f1_text = f1.read()
with open('show_run_SW-VSS_2019-02-01.txt') as f2:
    f2_text = f2.read()



delta_html = HtmlDiff().make_file(f1_text.splitlines(),
                                  f2_text.splitlines())

with open('diff22.html', 'w') as f:
     f.write(delta_html)

Tuesday, 19 February 2019

mongo db query ( group , aggregate ) to fetch latest network backup




 db.backup.aggregate({$unwind: '$backupDoc'},{$match: { "backupDoc.status": "success" }},{$group: {"_id" : "$deviceIp",lastdate: {$max: "$backupDoc.datetime"}}

Saturday, 9 February 2019

Checking Firewall Status and Stopping Firewall in centos



[root@DSCenWeb01 ~]# sudo firewall-cmd --state
running
[root@DSCenWeb01 ~]# sudo systemctl stop firewalld

Friday, 8 February 2019

Celery Beat To Schedule Multiple Tasks




CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Kolkata'
CELERY_BEAT_SCHEDULE = {
    'NetworkBackup': {
      'task': 'NetworkAutomation.views.bkpSchedule',
      #'schedule': timedelta(seconds=3600),
      'schedule': crontab(minute=0, hour="*/6"),
    },
    'copyBkpFromAnsibletoJenkins': {
      'task': 'NetworkAutomation.views.copyBkpFromAnsibletoJenkins',
      #'schedule': crontab(minute="*/3"),
      'schedule': crontab(minute=0, hour="*/1"),
    },
    'copyBkpFromJenkinstoDjango': {
      'task': 'NetworkAutomation.views.copyBkpFromJenkinstoDjango',
      #'schedule': crontab(minute="*/2"),
      'schedule': crontab(minute=0, hour="*/1"),
    },

}

Thursday, 7 February 2019

SCP to Copy all files inside a directory from remote linux host using sshpass



 "sshpass -p '<password>' scp -r root@<remoteIP>:<sourcepath> <destinationpath>"

Django Celery task to copy file from remote host using SCP and SSHPASS



@task()
def copyBkpFromJenkinstoDjango():
       ip = ''
       port = ""
       username = ""
       password = ""
       cmd = "sshpass -p '<password>' scp -r root@<remoteIP>:/root/networkBackups /root/Django"
       #print (cmd)
       ssh=paramiko.SSHClient()
       ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
       ssh.connect(ip,port,username,password)
       stdin,stdout,stderr=ssh.exec_command(cmd)
       time.sleep(50)
       outlines=stdout.readlines()
       resp =''.join(outlines)
       #print(resp)
       return resp

Wednesday, 6 February 2019

Moving all files from one directory to another using Python


import shutil
import os
source = '/path/to/source_folder'
dest1 = '/path/to/dest_folder'

files = os.listdir(source)

for f in files:
        shutil.move(source+f, dest1)

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...