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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending ping output to text file? 1

Status
Not open for further replies.

Hansenator

Technical User
Apr 18, 2009
2
Hello,

I'm very new to Perl and hope someone can help.

I'm trying to write a program for linux that opens a file, pings the addresses in the file and sends the output to an output file and to the screen.

I searched on the internet and tried it every way I can think of but can't get it to work. This is what I have so far that does work, it will open a file, ping the addresses and send the output to the screen but I can't figure out how to send that same output to another file:

Code:
#!/usr/bin/perl

while (defined($line = <>)) {
	system ("ping -c 4 $line");
}

Thanks so much for the help.
 
Use backticks instead of system

Code:
my $out = `ping -c 4 $line`;

Then the output goes into $out, which you can then print to the screen and also write to a file.

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top