Automatizando Backup de OLTs Fiberhome via terminal

Share Button

English title: Automating Backups of Fiberhome OLTs over line comand

downloadbk-olt-fiberhome.py é um simples script para automatização de backup de OLTs Fiberhome, sem a necessidade do software de gerencia ANM2000 instalado.

Usage
./bk-olt-fiberhome.py IP_ADDRESS

Configuration
Don’t forgot to configure all variables in file bk-olt-fiberhome.py
=======================================================================
user = ‘GEPON’
password = ‘GEPON’
FTPSERVER = ‘200.200.200.200’
ftpuser = ‘user’
ftppassword = ‘123456’
=======================================================================

Link para o GitHub


#!/usr/bin/python
#-------------------------------------
#by Jorge Luiz Taioque
#jorgeluiztaioque at gmail dot com
#www.networktips.com.br
#-------------------------------------
#backup OLTs and ONUs fiberhome
#Usage 
#./bk-olt-fiberhome.py IP_ADDRESS


import sys,pexpect
import getpass
import time

HOST = sys.argv[1]

#configure here all variables following you system 
#=======================================================================
user = 'GEPON'
password = 'GEPON'
FTPSERVER = '200.200.200.200'
ftpuser = 'user'
ftppassword = '123456'
#=======================================================================


child = pexpect.spawn ('telnet '+HOST) #option needs to be a list
child.timeout = 150
child.logfile = sys.stdout #display progress on screen

#loging to OLT IP
time.sleep(2)
child.expect ('Login: ') #waiting for login
child.sendline (user) #sending login name
child.expect('Password:') #waiting for password
child.sendline (password) #sending password
child.expect('>')

time.sleep(3)

#go up enable configuration
child.sendline ('EN'+'\r') #going to ENABLE configuration
child.expect('Password:') #waiting enable password
child.sendline (password) #sending enable password 
time.sleep(3)
child.expect('#')

#sending commando to copy configuration file to remote FTP server
child.sendline ('upload ftp config '+FTPSERVER+' '+ftpuser+' '+ftppassword+' bk-olt-'+HOST+'-.cfg')
time.sleep(10)

#exiting connection
child.expect('#')
child.sendline ('exit \r')
child.sendline ('exit \r')

Switch-backup.py – Script para backup de switch gerenciaveis

Share Button

English Title: switch-backup.py a script to make backup of manageable switchs.

Um simples script para automatizar a tarefa de coletar as informações de um switch e armazená-las em um servidor TFTP.

Eu utilizo a mesma estrutura de script para realizar backup em switchs, TP-Link, DELL e Cisco, bastando alterar simplesmente a sequencia que os comandos são enviados e como o copy para o servidor TFTP deve ser feito.

Esse script funciona perfeitamente nos modelos da TP-Link:
TL-SG2216
TL-SG2424

Github

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python
#Script starts here
 
 
import sys,pexpect
import getpass
import time
 
HOST = '10.10.10.1'
user = 'admin'
password = 'passworc'
TFTPSERVER = '200.200.200.200'
 
child = pexpect.spawn ('telnet '+HOST) #start telnet session in switch
child.timeout = 30
child.logfile = sys.stdout #display progress of script on screm
 
time.sleep(2)
 
child.expect ('User:') #wait user
 
child.sendline (user+'\r') #send user
 
child.expect('Password:') #wait password
 
child.sendline (password+'\r') #send password
 
child.sendline ('\r')
 
time.sleep(2)
 
child.sendline (' enable\n'+'\r') #change mode to enable mode
 
child.expect('#') #wait # enable mode
 
child.sendline ('copy startup-config tftp ip-address '+TFTPSERVER+' filename bksw-'+HOST+ '\r') #send command to upload startup-config to TFTP server
time.sleep(2)
 
child.sendline ('logout \r') #exit switch console