I'm using Perl Expect module for my SSH connections. I already have a module using sub functions like this:
$exp->spawn("ssh -o ConnectTimeout=$connectTimeout $user\@$ip") or die ("unable to spawn \n");
@obj=$exp->expect( $commandTimeout,
[ qr/.*$quotedhostname.*/ => sub
{
print "connected \n";
$exp->send("term length 0", "\n");
$exp->expect($commandTimeout2,);
&executeCommands();
}
],
But my $quotedhostname is UPPERCASE. I need to catch this when it is LOWERCASE too. Isn't there a way to do something like this:
[ qr/.*$quotedhostname.*/ OR /.*$lowercasequotedhostname.*/ => sub
Or should I just have to add another [qr]
block ?
Add a /i
flag to make the match case-insensitive:
[ qr/$quotedhostname/i => sub
You also don't need the .*
at the start and end, it'll match anyway (they only serve to make it slower here).