#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::SSH::Perl; use Fcntl qw(:flock); use Config::IniFiles; my $path = 'conf.ini'; $| = 1; sub devices { open my $fh , '<' , "".$path."" or die "Could not open file: ".$path." - $!\n"; flock($fh, LOCK_SH) or die "Could not lock '".$fh."' - $!\n"; tie my %ini, 'Config::IniFiles', ( -file => "".$path."" ) or die "Error: IniFiles->new: @Config::IniFiles::errors"; close ($fh) or die "Could not close '".$fh."' - $!\n"; print Dumper(\%ini); my @keys = keys (%ini); my @data; my @loop; foreach my $hash (@keys) { @loop = clk_sync( $ini{$hash}{IP}, $ini{$hash}{user}, $ini{$hash}{psw}, $ini{$hash}{prompt}, $ini{$hash}{port} ); push(@data,@loop); } print Dumper(\@data); return @data; } # end sub complex my @list = devices(); sub clk_sync { my $host = shift; my $user = shift; my $passwd = shift; my $prompt = shift; my $port = shift; my $ssh = Net::SSH::Perl->new( $host , port => $port , protocol => 2 , interactive => 1 , batchMode => 1 , RhostsAuthentication => 1, debug => 0 ); $ssh->login($user,$passwd); my $cmd = "pwd"; #my $cmd = "sudo ntpdate ntp.ubuntu.com"; my($stdout, $stderr, $exit) = $ssh->cmd($cmd); $ssh->cmd("exit"); return $stdout; } __END__ $VAR1 = { 'Device 1' => { 'IP' => 'IP', 'user' => 'USER', 'psw' => 'PASSWORD', 'prompt' => '/[\\$%#>] $/', 'port' => 'PORT', 'hostname' => 'ubuntu' }, 'Device 2' => { 'IP' => 'IP', 'user' => 'USER', 'psw' => 'PASSWORD', 'prompt' => '/[\\$%#>] $/', 'port' => 'PORT', 'hostname' => 'ubuntu' } }; $VAR1 = [ '/home/Operating ', '/home/Operating ' ]; $VAR1 = [ undef, undef ];