Hello PerlMonks !! Here i am seeking for your Wisdom again ^^

My goal is to auto save the configuration parameters of a router Netcomm 140w.

The procedure is to connect to the router with ssh and use the following commands to create the backup conf file:

# cd /tmp # dbcfg_export -o /tmp/filename.cfg -p "password" # tar -C /usr/local/cdcs -zcvf - ipsec.d openvpn-keys ssh-hostkeys | o +penssl des3 -salt -k "password" | dd of=/tmp/vpn.des3 # tar -zcvf /opt/cdcs/upload/filename.cfg.tar.gz filename.cfg vpn.des3

The second command will create the file "/tmp/filename.cfg". In the end the backup conf file created is "/opt/cdcs/upload/filename.cfg.tar.gz" wich I will next recover via SCP

Below an exemple with filename = test and with no password. Don't bother with the missing files with the 1st tar command warning;

root:/# cd /tmp root:/tmp# dbcfg_export -o /tmp/test.cfg -p "" root:/tmp# tar -C /usr/local/cdcs -zcvf - ipsec.d openvpn-keys ssh-hos +tkeys | openssl des3 -salt -k "" | dd of=/tmp/vpn.des3 ipsec.d/ ipsec.d/crls/ ipsec.d/aacerts/ ipsec.d/policies/ ipsec.d/cacerts/ ipsec.d/certs/ ipsec.d/rsakey/ ipsec.d/private/ ipsec.d/ocspcerts/ tar: openvpn-keys: Cannot stat: No such file or directory ssh-hostkeys/ ssh-hostkeys/ssh_host_dsa_key ssh-hostkeys/ssh_host_rsa_key.pub ssh-hostkeys/ssh_host_ecdsa_key.pub ssh-hostkeys/ssh_host_key ssh-hostkeys/ssh_host_rsa_key ssh-hostkeys/ssh_host_dsa_key.pub ssh-hostkeys/ssh_host_key.pub ssh-hostkeys/ssh_host_ecdsa_key WARNING: can't open config file: /lib/ssl/openssl.cnf tar: Exiting with failure status due to previous errors 9+1 records in 9+1 records out 4792 bytes (4.7KB) copied, 0.081756 seconds, 57.2KB/s root:/tmp# tar -zcvf /opt/cdcs/upload/test.cfg.tar.gz test.cfg vpn.des +3 test.cfg vpn.des3

Now here my perl code, filename = test2 with no password

#!/usr/bin/perl -w ###################################### Perl Script ################### +############################### ## + ## ## + ## ## Auteur: WILLIAMS Temoe + ## ## Date: 21/04/16 + ## ## Description: The script will create a backup conf fi +le 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');

Now we can see the problem by comparing the size of the created files

root:/tmp# ll /tmp/t* -rw-r--r-- 1 root root 31331 Apr 28 13:55 /tmp/test.cfg -rw-r--r-- 1 root root 31331 Apr 28 13:58 /tmp/test2.cf +g root:/tmp# ll /opt/cdcs/upload/ -rw-r--r-- 1 root root 12548 Apr 28 13:55 test.cfg.tar. +gz -rw-r--r-- 1 root root 20 Apr 28 13:58 test2.cfg.tar +.gz

I suppose that the problem comes from the 3rd command but I can't explain why

Can you please help me with this ? Best regards. Temoe


In reply to Backup Script Pb by WTem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.