J
jm-1
Hi
I have not programmed before and I am doing my best to get to grips
with Perl in order to decode and modify a backup script. Could anyone
please explain the following line in plain english to me? I understand
that what we are saying is "While the file handle <CONFIG> is
available, chomp the newline character of off each line as we read it"
and then I am lost. Sorry to sound so thick! I am working my through
the tutorials but I am under pressure to get this script working. I
have pasted the entire script at the bottom of this message.
while (<CONFIG>)
{
chomp;
if (m/^\w/)
{
($key, $data) = split /=/, $_;
$array{$key} = $data;
}
}
Thanks for any help
Andy
#!/usr/bin/perl
use Expect;
use IO::Socket;
#Declare the varibles
my ($hour, $min, $sec, $now, $remoteip, $port, $connected, $ping);
my (@ports, @lines, %status);
#Delete know hosts file for ssh
$command = "/bin/rm -f /root/.ssh/known_hosts";
system($command);
#Open config file.
##if (!(open(CONFIG, "pix_backup.cfg")))
#{
# die "Emergency: Error: Cannot open configuration file";
#}
#Read contents of config file into a hash
#while (<CONFIG>)
#{
#chomp;
# if (m/^\w/)
#{
# ($key, $data) = split /=/, $_;
# $array{$key} = $data;
#}
#}
#Initialise variables read from the config file
my @ports = ("22");
$outputdir = $array{outputdir};
$firewall = $array{firewall};
$username = $array{username};
$password = $array{password};
# Get name of host list file from command line
#GetOptions ('f=s' => \$config_file);
# Decrypt host config file.
$config_file = "/var/scripts/host.lst";
#$ccrypt_key = "*************************";
#$command = "ccrypt -q -K $ccrypt_key -d $config_file.cpt";
#system($command);
#Open host config file.
if (!(open(HOSTS, $config_file)))
{
die "Emergency: Error: Cannot open host file";
}
# Read contents of config file into an array
@firewalls = <HOSTS>;
# EnCrypt host config file
#$command = "ccrypt -q -K $ccrypt_key -e $config_file";
#system($command);
# Loop through all the hosts in the config file to grab all the configs
for ($i=0; $i < @firewalls; $i++)
{
$string = $firewalls[$i];
chomp($string);
# Split out host to work on
@host = split /,/, $string;
# Set all the host variables
$Hostname = $host[0];
$HostIP = $host[1];
$UserName = $host[2];
$Password = $host[3];
$Enable_Password = $host[4];
$command = "perl /var/scripts/pix_get.pl -h $Hostname";
system($command);
##print $data;
} # End For
print "\n[FINISHED]\n\n"
I have not programmed before and I am doing my best to get to grips
with Perl in order to decode and modify a backup script. Could anyone
please explain the following line in plain english to me? I understand
that what we are saying is "While the file handle <CONFIG> is
available, chomp the newline character of off each line as we read it"
and then I am lost. Sorry to sound so thick! I am working my through
the tutorials but I am under pressure to get this script working. I
have pasted the entire script at the bottom of this message.
while (<CONFIG>)
{
chomp;
if (m/^\w/)
{
($key, $data) = split /=/, $_;
$array{$key} = $data;
}
}
Thanks for any help
Andy
#!/usr/bin/perl
use Expect;
use IO::Socket;
#Declare the varibles
my ($hour, $min, $sec, $now, $remoteip, $port, $connected, $ping);
my (@ports, @lines, %status);
#Delete know hosts file for ssh
$command = "/bin/rm -f /root/.ssh/known_hosts";
system($command);
#Open config file.
##if (!(open(CONFIG, "pix_backup.cfg")))
#{
# die "Emergency: Error: Cannot open configuration file";
#}
#Read contents of config file into a hash
#while (<CONFIG>)
#{
#chomp;
# if (m/^\w/)
#{
# ($key, $data) = split /=/, $_;
# $array{$key} = $data;
#}
#}
#Initialise variables read from the config file
my @ports = ("22");
$outputdir = $array{outputdir};
$firewall = $array{firewall};
$username = $array{username};
$password = $array{password};
# Get name of host list file from command line
#GetOptions ('f=s' => \$config_file);
# Decrypt host config file.
$config_file = "/var/scripts/host.lst";
#$ccrypt_key = "*************************";
#$command = "ccrypt -q -K $ccrypt_key -d $config_file.cpt";
#system($command);
#Open host config file.
if (!(open(HOSTS, $config_file)))
{
die "Emergency: Error: Cannot open host file";
}
# Read contents of config file into an array
@firewalls = <HOSTS>;
# EnCrypt host config file
#$command = "ccrypt -q -K $ccrypt_key -e $config_file";
#system($command);
# Loop through all the hosts in the config file to grab all the configs
for ($i=0; $i < @firewalls; $i++)
{
$string = $firewalls[$i];
chomp($string);
# Split out host to work on
@host = split /,/, $string;
# Set all the host variables
$Hostname = $host[0];
$HostIP = $host[1];
$UserName = $host[2];
$Password = $host[3];
$Enable_Password = $host[4];
$command = "perl /var/scripts/pix_get.pl -h $Hostname";
system($command);
##print $data;
} # End For
print "\n[FINISHED]\n\n"