Hello,
I have written a perl script that reads information form text file and executes some commands.
use strict;
use warnings;
use autodie;
use Net::SSH::Expect;
# ssh into a router
my $ssh = Net::SSH::Expect->new(
host => "ipaddr",
password => 'user',
user => 'pwd',
raw_pty => 1,
);
my $login_output = $ssh->login();
# execute the commands
$ssh->exec("command 1");
$ssh->exec("command 2");
# open a file and read the config information
open my $prep, '<', 'config.txt;
while (my $config = <$prep>) {
chomp $config;
my $conf = $ssh->exec("$config");
print("$conf");
}
the above code works and provides the required output.
However i would like to convert this code into a function so that i can reuse this for various config files.
For instance:
If I make the following function call
config_function("config2.txt");
The script should read that 2nd config file and execute the commands.Is it possible to do that.? suggestions please.