Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start a new perl script within a perl script

Status
Not open for further replies.

timgerr

IS-IT--Management
Joined
Jan 22, 2004
Messages
364
Location
US
I am trying to start a script within another script. I am running a windows computer and testing some firewall problems that we might have on some of our computers. I am pinging some computers.

Code:
 use strict;
 use String::Strip;

my $read_list = "U:\\scripts\\Perl\\scs_rights\\computers.txt";
open(READ, $read_list);

my $arg = 'U:\\scripts\\Perl\\scs_rights\\find_rights.pl ';


my $rec;
while ($rec = <READ>)
{
	my $out = system("ping " . $rec . " -n 1");
	

 		if ($out != '256') 
 		{
			system($arg . $rec)
			 			
 		}
 }
 close READ;

I want to part system($arg . $rec)to start in a new command window. The reason for this is that this new script has some code that can hang and I want to be able to terminat this command window without killing the main script.

thanks
Timgerr

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Tim, look up ping at CPAN, Net::Ping should be what you need, and you can do it all inline - the way you're trying I don't think will work, because of the way system() works. IIRC

You could write logfiles for each ping and then grep/parse them if you still want to use the ping in the command console

Also, I'd use forward slashes(/) instead of escaped (\\) backslashes, jsut for readability and maintainability.



Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
PaulTEG, Thanks for this information, (now and in the past). The problem that I have is not the ping part (I know that I could have done it a different way) but I need to start another perl script in a new windows command window. The reason for this is so I can kill the second command window if it hangs and the parent window will still run the master script. I am trying to connect to the admin share on windows computers seeing if the new firewall rules will allow me to do so. If the rules are not correct then it can take up to 5 minutes to the command to time out. I have to many computers to wait for this to happen. I want to be able to manuly kill the second child window. Any way to do this???


Thanks

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Win32::AdminMisc or some other of Dave Roth's modules could be just what you're looking for here.

What does the find_rights.pl script do?
 
Here is the 2 scripts, the first one is called ping and the second one is find_rights.

ping:
Code:
 # 1. This script is going to open a file and get computer names from it.  
 # 2. It will then ping a computer to see if it is live.
 # 3. This another script will be called "find_rights.pl".  The reason for this is so we can kill the child script and not the parent 
 		# script if the child script hangs.
 		
 use strict;
 use String::Strip;

my $read_list = "U:\\scripts\\Perl\\scs_rights\\computers.txt";
open(READ, $read_list);

my $arg = 'U:\\scripts\\Perl\\scs_rights\\find_rights.pl ';


my $rec;
while ($rec = <READ>)
{
	my $out = system("ping " . $rec . " -n 1");
	

 		if ($out != '256') 
 		{
			system("cmd " . $arg . $rec)
			 			
 		}
 }
 

 close READ;

find_rights
Code:
# This file will take an argument from ping.pl and see if we can connect to the admin$ share.
	# The reason why I am doing this with 2 scripts is I can then kill one of the scripts and not kill the parent one

use String::Strip;


# Opening a file to write too
my $write_list = "U:\\scripts\\Perl\\scs_rights\\rights_test.txt";
open(WRITE, ">>$write_list");


# Get the a ll the values for current time
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time) ; 
$time = "$Hour:$Minute:$Second";





print "----( Trying $ARGV[0] $time )---->  ";
StripTSpace($ARGV[0]); # stripping out all the not needed white space
if (-e '\\\\' . $ARGV[0] . '\\admin$\\explorer.exe')
{
	print " $ARGV[0] Can Connect\n";
	print WRITE "$ARGV[0] Can Connect\n";
}
else 
{	
	print " $ARGV[0] Failed\n";
	print WRITE "$ARGV[0] Failed\n";
}

close WRITE;

If needed be I want to be able to manualy close the second command window

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Win32::NetAdmin and Win32::AdminMisc are definitely worth a look for this

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top