Anthony, Mark. Please bottom-post so that people can understand the conversation. Thanks.
Anthony J Segelhorst wrote: > > Mark wrote: > > > > Anthony J Segelhorst wrote: > > > > > I am strapped for time on the run time on a perl script I > > > have been working on. > > > > > > I was wondering if it is possible to open another shell > > > within a perl script that will call another script that > > > uses another processes. > > > > > > If I call script B from script A, script A will not > > > complete until script B is done running. Is there a way > > > to run script B within another shell or process? > > > > But you want to run them in parallel? You will need threads. > > I do not think I need to run them in parallel. I just need > scripta.pl to finish in under 60 seconds and scriptb.pl can > take as long as it needs to. Scriptb.pl is only called when > scripta.pl needs to call it. > > I got some info on this: % perldoc -f fork > > I am confused about the syntax of the fork though. Does > anyone have any examples? >Hi Anthony. >Can you explain why you want to shell out to another Perl >process? I gathered from your description that you wanted to >speed up your application by accessing a bottleneck in parallel. >If your new process is started synchronously then you will gain >no speed advantage. >What version of Perl are you working with? Perl v5.8 has much >enhanced multithreading functionality. >Cheers, >Rob Basically I am writing the script to monitor services on Windows Servers using net start and it reads in a config file, that the end user builds. I want to attempt tp restart the service using a net start "Service Name", but the monitoring product I am importing the script into, only allows me to have a window of 60 seconds to run a script. This is the reason I am wanting to call an external script and the original script does not wait on the service to restart. The section where I restart the service, is where I need to call the external script, and have this script keep running without waiting on any return values: Code $servicestatus = 1; $lcf_tools = $ENV{LCF_TOOLSDIR}; $logfile = "$ENV{LCF_DATDIR}\\LCFNEW\\Tmw2k\\Service_Monitor\\service_monitor.log"; $netstart = "$ENV{LCF_DATDIR}\\LCFNEW\\Tmw2k\\bin\\net start"; $LOGMAX = 50000; $threshold = "c:\\SRV\\tools\\ITM\\mwv-service-monitor.conf"; ($dev,$inode,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($logfile); if ( $size > $LOGMAX ) { system ( "del $logfile" ); open( LOGFILE, "> $logfile" ); } else { open( LOGFILE, ">> $logfile" ); } ################### # #MAIN # # ################## open(IN,"$threshold") or &DefaultAction(); print LOGFILE "******************************\n"; $date = &Date; print LOGFILE "$date\n"; print LOGFILE "This server has a config file in use. $threshold\n"; while((defined(IN)) && ($line=<IN>)){ chomp $line; if ($line eq ""){ } else{ ($service,$severity,$group) = split("@", $line); # $service =~ tr/[A-Z]/[a-z]/; @linecountarray = `"$netstart |$lcf_tools\\grep "$service" |$lcf_tools\\wc -l"`; #loops through foreach only one time foreach $linetemp (@linecountarray){ ($linecount) = split(" ", $linetemp); $output = ""; &AnalyzeService($service); #$output set from &AnalyzeService } if (length($output) != 0){ print "$output"; print LOGFILE "The results from the script are:\n"; print LOGFILE "$output\n"; print LOGFILE "******************************\n"; } } } #if all services in config running prints OK if($servicestatus == 1){ print "OK\n"; print LOGFILE "The results from the script are:\n"; print LOGFILE "OK\n"; print LOGFILE "******************************\n"; } exit(0); #if no config file exits, because there are no services to monitor sub DefaultAction{ print LOGFILE "******************************\n"; $date = &Date; print LOGFILE "$date\n"; print LOGFILE "There is no config file for this server\n"; print LOGFILE "With no config file, there is no services to monitor\n"; print LOGFILE "Now exiting\n"; print "OK\n"; exit(0); } #$linecount== -> |grep wc -l returned 0 and service not running sub AnalyzeService{ if ($linecount == 0){ $servicestatus = 0; print LOGFILE "The service named $service is NOT started\n"; $output = "WinService,$severity,$service,$group;"; #Try to restart service # #THIS is where I need to call an external script that does the net start and this script just keeps going. `$netstart "$service" /y`; print LOGFILE "Attempted to restart the service called $service\n"; } else{ print LOGFILE "The service named $service is started\n"; # print "The service named $service is started\n"; } } #MWV Data routine sub Date { my($sec,$min,$hour,$dom,$mon,$year,$wday,$yday,$isdst) = localtime(time()); my(@months) = ("Jan","Feb","March","April","May","June","July","August","Sep","Oct","Nov","Dec"); my(@week) = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); $year = $year + 1900; if ( $sec < 10 ) { $sec = 0 . $sec; } if ( $min < 10 ) { $min = 0 . $min; } if ( $hour < 10 ) { $hour = 0 . $hour; } my($date) = "$week[$wday] $months[$mon] $dom $hour:$min:$sec $year"; return $date; } Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] "Rob Dixon" <[EMAIL PROTECTED]> 10/28/2003 10:58 AM To: [EMAIL PROTECTED] cc: Subject: Re: Opening a new shell Anthony, Mark. Please bottom-post so that people can understand the conversation. Thanks. Anthony J Segelhorst wrote: > > Mark wrote: > > > > Anthony J Segelhorst wrote: > > > > > I am strapped for time on the run time on a perl script I > > > have been working on. > > > > > > I was wondering if it is possible to open another shell > > > within a perl script that will call another script that > > > uses another processes. > > > > > > If I call script B from script A, script A will not > > > complete until script B is done running. Is there a way > > > to run script B within another shell or process? > > > > But you want to run them in parallel? You will need threads. > > I do not think I need to run them in parallel. I just need > scripta.pl to finish in under 60 seconds and scriptb.pl can > take as long as it needs to. Scriptb.pl is only called when > scripta.pl needs to call it. > > I got some info on this: % perldoc -f fork > > I am confused about the syntax of the fork though. Does > anyone have any examples? Hi Anthony. Can you explain why you want to shell out to another Perl process? I gathered from your description that you wanted to speed up your application by accessing a bottleneck in parallel. If your new process is started synchronously then you will gain no speed advantage. What version of Perl are you working with? Perl v5.8 has much enhanced multithreading functionality. Cheers, Rob Basically I am writing the script to monitor services on Windows Servers using net start and it reads in a config file, that the end user builds. I want to attempt tp restart the service using a net start "Service Name", but the product I am importing the script into, only allows me to have a window of 60 seconds to -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ________________________________________________________________________ This email has been scanned for all viruses by the MessageLabs SkyScan service._______________________________________________________________ ________________________________________________________________________ This email has been scanned for all viruses by the MessageLabs SkyScan service._______________________________________________________________ Note: Please update your email address for this user to reflect the new MeadWestvaco Corporation. MeadWestvaco employee email addresses are in the format of [EMAIL PROTECTED] This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] _______________________________________________________________________