Passing Parameteres to Interactive script programatically

49 Views Asked by At

We have an interactive script(Script 1) which asks for an IP Address and continues it's execution process. Script 1 is called from script2. As we know the IP address we want to pass IP Automatically to script so that manual intervention is not required

I looked into Expect Module. But i cannot install that module in PRODUCTION server.

Can someone suggest a way to overcome this issue.

1

There are 1 best solutions below

0
Subhash On

Try this,

#script2.pl

use strict;
use warnings;

use Getopt::Long;

GetOptions (
"ipAddress=s" => \$ip,
) or die("Enter IP address");

my $cmd = "perl script1.pl --ip=$ip";
system($cmd);

.

#script1.pl

use strict;
use warnings;

use Getopt::Long;
GetOptions (
"ip=s" => \$ip,
) or die("Enter IP address");

print "IP address is $ip";

Execute like this.

perl script2.pl --ipAddress=10.11.12.13

If you want to execute script1 directly, can execute like this,

perl script1.pl --ip=10.11.12.13