filmov
tv
Python learning for Network Engineers | Part 16 |Cisco backup script string formatting add timestamp

ะะพะบะฐะทะฐัั ะพะฟะธัะฐะฝะธะต
๐๐ผ๐ฟ ๐๐ผ๐บ๐ฝ๐น๐ฒ๐๐ฒ ๐ฃ๐๐๐ต๐ผ๐ป ๐๐ผ๐ฟ ๐ก๐ฒ๐๐๐ผ๐ฟ๐ธ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ๐ ๐๐ผ๐๐ฟ๐๐ฒ:
๐๐ป๐ฟ๐ผ๐น๐น ๐ณ๐ผ๐ฟ ๐ฏ๐ฒ๐น๐ผ๐ ๐จ๐ฑ๐ฒ๐บ๐ ๐๐น๐ฎ๐๐: ๐๐๐๐ ๐๐๐ซ๐ฌ๐ข๐จ๐ง
๐ซ๐๐๐๐๐๐๐๐๐ ๐น๐๐๐๐๐๐๐ ๐ณ๐๐๐:
To stay updated with my latest videos Please subscribe to my channel by clicking below
#CiscoPythonBackup
#PythonStringFormatting
#PythonTimeFormatting
This video demonstrates string formatting in python 3.
Different types of string formatting eg %s %i in python
Shows how to format time stamp data in python using, type formatting
print (TNOW.day)
print (TNOW.month)
print (TNOW.year)
print (TNOW.hour)
print (TNOW.minute)
print (TNOW.second)
print (str(TNOW.day) +'-'+str(TNOW.month)+'-'+str(TNOW.year)+'_'+ str(TNOW.hour) + '-' +str(TNOW.minute) + '-' + str(TNOW.second) )
print("%.2i-%.2i-%i_%.2i-%.2i-%.2i" % (TNOW.day,TNOW.month,TNOW.year,TNOW.hour,TNOW.minute,TNOW.second))
help() : FORMATTING
'{:%d-%m-%Y_%H:%M:%S}'.format(TM)
TFORMAT = '{:%d-%m-%Y_%H:%M:%S}'.format(TNOW)
print(TFORMAT)
Sample Script
import paramiko
import time
from getpass import getpass
import datetime
TFORMAT = '{:%d-%m-%Y_%H:%M:%S}'.format(TNOW)
username = 'admin'
password = 'admin'
scp_pass = getpass( prompt = 'Enter SCP server Password :')
DEVICE_LIST = open ('09_devices')
for RTR in DEVICE_LIST:
RTR = RTR.strip()
print ('\n #### Connecting to the device ' + RTR + '####\n' )
SESSION = paramiko.SSHClient()
SESSION.set_missing_host_key_policy(paramiko.AutoAddPolicy())
SESSION.connect(RTR,port=22,
username=username,
password=password,
look_for_keys=False,
allow_agent=False)
DEVICE_ACCESS = SESSION.invoke_shell()
DEVICE_ACCESS.send(scp_pass +'\n')
print ('Backup completed for the device ' + RTR + '\n\n')
SESSION.close
๐๐ป๐ฟ๐ผ๐น๐น ๐ณ๐ผ๐ฟ ๐ฏ๐ฒ๐น๐ผ๐ ๐จ๐ฑ๐ฒ๐บ๐ ๐๐น๐ฎ๐๐: ๐๐๐๐ ๐๐๐ซ๐ฌ๐ข๐จ๐ง
๐ซ๐๐๐๐๐๐๐๐๐ ๐น๐๐๐๐๐๐๐ ๐ณ๐๐๐:
To stay updated with my latest videos Please subscribe to my channel by clicking below
#CiscoPythonBackup
#PythonStringFormatting
#PythonTimeFormatting
This video demonstrates string formatting in python 3.
Different types of string formatting eg %s %i in python
Shows how to format time stamp data in python using, type formatting
print (TNOW.day)
print (TNOW.month)
print (TNOW.year)
print (TNOW.hour)
print (TNOW.minute)
print (TNOW.second)
print (str(TNOW.day) +'-'+str(TNOW.month)+'-'+str(TNOW.year)+'_'+ str(TNOW.hour) + '-' +str(TNOW.minute) + '-' + str(TNOW.second) )
print("%.2i-%.2i-%i_%.2i-%.2i-%.2i" % (TNOW.day,TNOW.month,TNOW.year,TNOW.hour,TNOW.minute,TNOW.second))
help() : FORMATTING
'{:%d-%m-%Y_%H:%M:%S}'.format(TM)
TFORMAT = '{:%d-%m-%Y_%H:%M:%S}'.format(TNOW)
print(TFORMAT)
Sample Script
import paramiko
import time
from getpass import getpass
import datetime
TFORMAT = '{:%d-%m-%Y_%H:%M:%S}'.format(TNOW)
username = 'admin'
password = 'admin'
scp_pass = getpass( prompt = 'Enter SCP server Password :')
DEVICE_LIST = open ('09_devices')
for RTR in DEVICE_LIST:
RTR = RTR.strip()
print ('\n #### Connecting to the device ' + RTR + '####\n' )
SESSION = paramiko.SSHClient()
SESSION.set_missing_host_key_policy(paramiko.AutoAddPolicy())
SESSION.connect(RTR,port=22,
username=username,
password=password,
look_for_keys=False,
allow_agent=False)
DEVICE_ACCESS = SESSION.invoke_shell()
DEVICE_ACCESS.send(scp_pass +'\n')
print ('Backup completed for the device ' + RTR + '\n\n')
SESSION.close
ะะพะผะผะตะฝัะฐัะธะธ