0

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.

pynexj
  • 19,215
  • 5
  • 38
  • 56
  • 2
    Rewrite script 1 so that it takes a parameter rather than being interactive. – William Pursell Apr 06 '17 at 11:49
  • Please [edit] your question to show [what you have tried so far](http://whathaveyoutried.com). You should include at least an outline (but preferably a [mcve]) of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Apr 06 '17 at 12:19
  • Unless it does something funky, just piping might work: `script2.pl | scrpit1.pl`. – Oleg V. Volkov Apr 06 '17 at 12:58

1 Answers1

0

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
Subhash
  • 568
  • 1
  • 5
  • 21