Using subprocess.call in python, I am trying to run a perl script, that runs a code on remote machines to fetch some information.
I have two scripts on machine A - python and perl. The python script calls the perl script using subprocess.call method by passing to it IP addresses in a loop. Both the scripts run just fine.
However, the perl script is executed in serial order (one IP after another).
# python code
def foo():
print()
IPs = ["198.168.1.2","198.168.3.4"]
for ip in IPs:
proc = call("perl script.pl '%s'" %ip, shell=True, stdin=PIPE)
foo()
# perl script
#!/usr/bin/perl
sub bar($)
{
//Code that ssh's to a remote-machine and gets required information
}
print(bar($ARGV[0]),"\n");
print("Sleeping for 15 sec\n");
sleep(15);
print("Done\n");
Actual behavior -
- The python script runs the perl script by passing '198.168.1.2'
- perl script executes the code and sleeps for 15 sec
- The python script then runs the perl script by passing ''198.168.3.4'
- perl script executes the code and sleeps for 15 sec
Hence total of 30 seconds are required to run perl script for both the IP's.
Expected behavior -
- The python script runs the perl script by passing '198.168.1.2'
- Instead of waiting for perl script to finish with the first IP, it executes the same perl script with '198.168.3.4'.
Hence the time taken for executing the perl script for both the IP's is more or less the same.