Hello,
I am trying to create a script that will compare two identical pieces of hardwares configuration files (that are added via a GUI provided as part of the device) and to synchronize the two devices configurations.
I currently have a shell script that connects to and downloads the configuration to the two devices and am struggling with the method in which to "merge" the two documents. I cannot have the configuration file completely replaced on each sync as that will wipe out historical data.
Shell script:
#!/bin/sh
# Script uses maint_dsa key for authentication.
cp ~/equinix-shaper.txt ~/equinix-shaper.txt.backup
cp ~/qwest-shaper.txt ~/qwest-shaper.txt.backup
echo Fetching Equinix Simple Queue
ssh -i ~/.ssh/maint_dsa admin-ssh@xxx.xx.xxx.x "queue simple export" > equinix-shaper.txt && sleep 5
echo Fetching Qwest Queue
ssh admin-ssh@yyy.yy.yyy.yy "queue simple export" > qwest-shaper.txt
Perl Script for Comparing - not working quite as I would like:
#! /usr/bin/env perl
use strict;
use warnings;
my $f1 = '/Users/anrima/equinix-shaper.txt';
my $f2 = '/Users/anrima/qwest-shaper.txt';
my $outfile = '/Users/anrima/shaper-difference.txt';
my %results = ();
open FILE1, "$f1" or die "File: $! does not exist \n";
while(my $line = <FILE1>){
$results{$line}=1;
}
close(FILE1);
open FILE2, "$f2" or die "File: $! does not exist \n";
while(my $line =<FILE2>) {
$results{$line}++;
}
close(FILE2);
open (OUTFILE, ">$outfile") or die "$outfile does not exist \n";
foreach my $line (keys %results) {
print OUTFILE $line if $results{$line} == 1;
}
close OUTFILE;
Could I maybe get a little help as I am new to programming in general and perl in particular (requirement of the job is in perl).