Hi I have a small program listed below where i am writing ping results to a file. The program works file except that the file name in the output file is coming as log_ping_19_Mar_15_11_27_49? (please note the ? at the end of the name)
The initial output looks like bats3 snemana/perlprogs> perl pingTest.pl hostInfo.txt Logfile is log_ping_19_Mar_15_11_38_53 File name is hostInfo.txt ............................. Could someone please tell why the ? is getting added to the file name although it looks fine in the initial print of the file name. use Data::Dumper; use strict; use warnings; my $numberOfPingPackets=1; my $fullFileName=$ARGV[0]; my $logFileName="log_ping_".`date +"%d_%b_%y_%H_%M_%S"`; print "\nLogfile is $logFileName"; print ("\nFile name is $fullFileName"); open FILE, $fullFileName or die $!; my $logFile; open $logFile, '>', $logFileName or die $!; my @fileContents=<FILE>; print ("\nFile contents are ".Dumper(@fileContents)); for(my $i=0;$i < @fileContents; $i++) { my $line=$fileContents[$i]; my @data=split(/\t/,$line); my $host=$data[0]; my $ip=substr($data[1],0,-1); my @pingResults=`ping -c $numberOfPingPackets $ip`; my $succesString="$numberOfPingPackets packets transmitted, $numberOfPingPackets received, 0% packet loss"; my $index=3+$numberOfPingPackets; if(index($pingResults[$index],$succesString) >= 0) { print "\nPing to host $host ip $ip is successful"; print $logFile "\nPing to host $host ip $ip is successful"; } else { print "\nPing to host $host ip $ip is failure"; print $logFile "\nPing to host $host ip $ip is failure"; } } close $logFile; -- Satya Prasad