In case you do want to use perl to do it, here is some possiblyhelpful example code:

----------------------------------------------------------------------------
use Net::Ping;
my $pingobj = Net::Ping->new('icmp', 3);

while (<>)
{
	my @line = split(';', $_);
	push @hosts, $line[2];
}

foreach $host (@hosts)
{
	$result = $pingobj->ping($host);
	print "host = $host, result = $result\n";
}
----------------------------------------------------------------------------

Warning: This code is untested. Good luck.

Troy

>>> dopp at acm.cs.umn.edu 02/27/01 04:03PM >>>
Well, there are already "standard" UNIX commands that can help you with
this.  I think you could do this with the cut:

If your file has fields delmited with some character (e.g. ;), then try

cut -d ";" -f 2 <flat-file-name> > temp-file 

should do it.  Then, you can do what you want with temp-file.  Write a perl
script to open it and ping whatever's on each line of the file. 

You can use perl to do it all if you want to - maybe it's a good learning
experience for you, but I firmly believe in the use of currently existing
tools... I mean, that's what they're there for, right? :)

Gabe

On Tue, Feb 27, 2001 at 03:12:40PM -0600, Rodney Ray wrote:
> Here is the deal. I want to use perl to ping a server and need to get the address from a flat file that has a fix file format. The field that I'm tring to get is the second column in the file. Any Perl experts that could help me get  this thing working on my box. The grep4=ntharg(entry,2,\":\");\ returns the the second field but I can't get ping to use the  the grep4. 
> 
> 
> 
> 
> 
> 
> 
> APPLICATIONS = { 
>   { NAME = "ROUTERS",
> 	ACTIVE = True,
> 	SECURITY = False,
> 	PROPAGATE_STATE = True,
> 	CREATE_ICON = True,
> 	SUSPEND_GLOBAL_PARAMS = False,
> 	SHOWINST = False,
> 	DISCOVERY_TIME = 60,
> 	DISCOVERY = PSL,
> 	PRE_DISCOVERY_TEXT =  922285734 "#unix_only.psl\
> 
> 
> PslDebug = 0;\
> \
> # if the config file doesn't exist, continue with pre-discovery only\
> #\
> if (file(get(\"/patrolHome\").\"/lib/local_alerts/network.config\")) {\
> 	set(\"active\",2);\
> 	}\
> else {\
> 	set(\"active\",1);\
> 	}",
> 	DISCOVERY_TEXT =  955039061 "#\
> DEBUG=0;\
> #\
> icons = get(\"/ROUTERS/instances\");\
> foreach y (icons)\
> {\
>    set(\"/ROUTERS/\".y.\"/online\",0);\
> }\
> #\
> #\
> infile = cat(get(\"/patrolHome\").\"/lib/local_alerts/network.config\");\
> #\
> #\
> foreach entry (infile) {\
> 	label=ntharg(entry,1,\":\");\
> 	grep4=ntharg(entry,2,\":\");\
> 	num_needed=ntharg(entry,3,\":\");\
> 	if (!exists(\"/ROUTERS/\".label)) {\
> 		create(label.\"-Master\",label,OK);\
> 	}\
> 	set(\"/ROUTERS/\".label.\"-Master/online\",1);\
> 	foreach proc (process(grep4)) {\
> 		cnt++;\
> #		pid = ntharg(proc,1);\
> #		set(\"/ROUTERS/\".pid.\"/online\",1);\
> #		if (!exists(pid)) {\
> #			create(pid,label.\"-\".pid,OK);\
> #			# turn off the alarm parameter for this instance\
> #			# - only need to see it for Master instances\
> #			set(\"/ROUTERS/\".pid.\"/PROProcAlarm/active\",0);\
> #		}\
> 	}\
> if (DEBUG) { print(\"\\nPID= \".pid); }\
> set(\"/ROUTERS/\".label.\"-Master/num_needed\",num_needed);\
> set(\"/ROUTERS/\".label.\"-Master/num_now\",cnt);\
> if ( cnt < num_needed) {\
> 	set(\"/ROUTERS/\".label.\"-Master/PROProcAlarm/value\",1);\
> }\
> else {\
> 	set(\"/ROUTERS/\".label.\"-Master/PROProcAlarm/value\",0);\
> }\
> cnt=0;\
> }\
> #\
> #  Remove instances that no longer exist\
> #\
> foreach z (icons)\
> {\
>    if( ! get(\"/ROUTERS/\".z.\"/online\") )\
>    {\
>       destroy(z);\
>    }\
> }\
> ",
> 	OK_PICTURE = "process_ok.xpm",
> 	WRONG_PICTURE = "process_warn.xpm",
> 	PARAMETERS = {
> 		{	NAME = "PROProcAlarm", PARAM_TYPE = CONSUMER, ACTIVE = True, MONITOR = True, CHECK = False,
> 				BASE_COMMAND = { 
> 				{ COMPUTER_TYPE = "ALL_COMPUTERS", COMMAND_TYPE = "OS",
> 				  COMMAND_TEXT =  845406750 "exit;"}
> 				},
> 			TITLE = "ProcessAlarm",
> 			HISTORY_TIME = "", HISTORY_SPAN = 16, HISTORY_LEVEL = False,
> 			FORMAT = "%f", OUTPUT = OUTPUT_STATEBOOLEAN,
> 			AUTO_RESCALE = False, Y_AXIS_MIN = 0, Y_AXIS_MAX = 1,
> 			RANGES = {
> 			  { NAME = "BORDER", ACTIVE = False, MINIMUM = 0, MAXIMUM = 0, STATE = OK, ALARM_WHEN = ALARM_INSTANT, ALARM_WHEN_N = 0
> 			  },
> 			  { NAME = "ALARM1", ACTIVE = False, MINIMUM = 0, MAXIMUM = 0, STATE = OK, ALARM_WHEN = ALARM_INSTANT, ALARM_WHEN_N = 0
> 			  },
> 			  { NAME = "ALARM2", ACTIVE = True, MINIMUM = 1, MAXIMUM = 1, STATE = ALARM, ALARM_WHEN = ALARM_INSTANT, ALARM_WHEN_N = 0
> 			  }
> 			}
> 		}
> 
> 	}
>   }
> }
> !30551
> 
> _______________________________________________
> tclug-list mailing list
> tclug-list at mn-linux.org 
> https://mailman.mn-linux.org/mailman/listinfo/tclug-list 

-- 
--------------------------------------------------------------------------------
Gabe Turner				       |  	   X-President,
UNIX Systems Administrator,		       | Assoc. for Computing Machinery
U of M Supercomputing Institute for	       |    University of Minnesohta
Digital Simulation and Advanced Computation    |       dopp at acm.cs.umn.edu 

"You've really lost it this time....you've lost your mind!"
	- Ren finds out about Stimpy's Stinky Butt Fantasy in "Son Of Stimpy"
--------------------------------------------------------------------------------
_______________________________________________
tclug-list mailing list
tclug-list at mn-linux.org 
https://mailman.mn-linux.org/mailman/listinfo/tclug-list