#!/usr/bin/perl -w ###################################### Perl Script ################################################## ## ## ## ## ## Auteur: WILLIAMS Temoe ## ## Date: 21/04/16 ## ## Description: The script will create a backup conf file of a router Netcomm 140W used for business clients ## ## ## ## ## ## ## ##################################################################################################### use strict; use warnings; #### Déclaration Bibliothèques use Net::SSH2; use Time::Piece; #### Déclaration Variables globales my $date = Time::Piece->new->strftime('%d-%m-%Y'); my $user='root'; my $password='W1m4x21h'; my $portssh=22; my $pwdfile=""; ################# Netcomm140w Backup process via SSH connexion ######################### ################# Use router @IP and client name as variables ######################### sub sauvegarde_netcomm { #### Variable declaration my($ip, $filename) = @_; #### Initialize SSH connexion my $ssh = Net::SSH2->new(); $ssh->connect($ip, $portssh) or die; if ($ssh->auth_password($user,$password)) { ## Command lines for the backup process my $chan = $ssh->channel(); $chan->shell(); $chan->blocking(0); print $chan "cd /tmp\n"; print $chan "dbcfg_export -o /tmp/$filename.cfg -p '$pwdfile'\n"; print $chan "tar -C /usr/local/cdcs -zcvf - ipsec.d openvpn-keys ssh-hostkeys | openssl des3 -salt -k '$pwdfile' | dd of=/tmp/vpn.des3\n"; print $chan "tar -zcvf /opt/cdcs/upload/$filename.cfg.tar.gz $filename.cfg vpn.des3\n"; #print $chan "rm -f /tmp/$filename.cfg\n"; #### Close SSH connexion $chan->close(); sleep (1); }else { #### Error message when ssh connexion fail warn "auth failed.\n"; } } ################# Main Program ######################################################## ################# Netcomm140w Backup ######################################################## sauvegarde_netcomm ('192.168.200.62' , 'test2');