http://www.perlmonks.org?node_id=961831


in reply to How to display the .pl process in command line

Okay... Can you post your code? I have several ideas for this, but I'd like to gear it to your particular context.

Replies are listed 'Best First'.
Re^2: How to display the .pl process in command line
by Anonymous Monk on Mar 27, 2012 at 05:42 UTC
    Here it goes much proper way to view: :)
    open(OUTFILE, ">", "check_result.txt") or die ("unable to write output +: $!"); my @url = ('www.yahoo.com', 'www.google.com' ); #for check Ping & c +heck TCP #check Ping print OUTFILE "*Ping Result*\n"; use Net::Ping; $p = Net::Ping->new("syn"); if ($p->ping($url2[0])) { print OUTFILE "$url2[0] is alive. \n"; } else { print OUTFILE "$url2[0] is not alive. \n"; } if ($p->ping($url2[1])) { print OUTFILE "$url2[1] is alive. \n\n"; } else { print OUTFILE "$url2[1] is not alive. \n\n"; } #check TCP Result use strict; use Socket; use Time::HiRes qw( gettimeofday ); use Net::hostent; print OUTFILE "*TCP Result*\n"; my $timeout = 3; my $hostname = ($url2[0]); my $hostname1 = ($url2[1]); my $portnumber = '80'; my $portnumber1 = '80'; my $host = shift || $hostname; my $host1 = shift || $hostname1; my $port = shift || $portnumber; my $port1 = shift || $portnumber1; my $proto = getprotobyname('tcp'); my $iaddr = inet_aton($host); my $iaddr1 = inet_aton($host1); my $paddr = sockaddr_in($port, $iaddr); my $paddr1 = sockaddr_in($port1, $iaddr1); socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; +#for casino.sbobet.com eval { local $SIG{ALRM} = sub { die "timeout" }; alarm($timeout); connect(SOCKET, $paddr) || error(); alarm(0); }; if ($^P) { close SOCKET || die "close: $!"; print OUTFILE "$hostname is NOT listening on tcp port $portnumber.\n +"; } else { close SOCKET || die "close: $!"; print OUTFILE "$hostname is listening on tcp port $portnumber."; my ($t02, $t12, $startTime2); $startTime2 = gettimeofday(); connect(SOCK, $paddr); $t02 = gettimeofday() - $startTime2; close (SOCK); $t02 = gettimeofday() - $startTime2, printf OUTFILE (" avg:%.8f", $t02); print OUTFILE ("ms\n"); } socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; #f +or casino1.sbobet.com eval { local $SIG{ALRM} = sub { die "timeout" }; alarm($timeout); connect(SOCKET, $paddr1) || error(); alarm(0); }; if ($ARGV) { close SOCKET || die "close: $!"; print OUTFILE "$hostname1 is NOT listening on tcp port $portnumber1. +\n"; } else { close SOCKET || die "close: $!"; print OUTFILE "$hostname1 is listening on tcp port $portnumber1."; my ($t02, $t12, $startTime2); $startTime2 = gettimeofday(); connect(SOCK, $paddr1); $t02 = gettimeofday() - $startTime2; close (SOCK); $t02 = gettimeofday() - $startTime2, printf OUTFILE (" avg:%.8f", $t02); print OUTFILE ("ms"); }
Re^2: How to display the .pl process in command line
by Anonymous Monk on Mar 27, 2012 at 05:38 UTC
    okay this code is just a check ping and check tcp here it is: note: that I didn't make the script just edit and modify as part of my learning :) open(OUTFILE, ">", "check_result.txt") or die ("unable to write output: $!"); my @url = ('www.yahoo.com', 'www.google.com' ); #for check Ping & check TCP #check Ping print OUTFILE "*Ping Result*\n"; use Net::Ping; $p = Net::Ping->new("syn"); if ($p->ping($url2[0])) { print OUTFILE "$url2[0] is alive. \n"; } else { print OUTFILE "$url2[0] is not alive. \n"; } if ($p->ping($url21)) { print OUTFILE "$url21 is alive. \n\n"; } else { print OUTFILE "$url21 is not alive. \n\n"; } #check TCP Result use strict; use Socket; use Time::HiRes qw( gettimeofday ); use Net::hostent; print OUTFILE "*TCP Result*\n"; my $timeout = 3; my $hostname = ($url2[0]); my $hostname1 = ($url21); my $portnumber = '80'; my $portnumber1 = '80'; my $host = shift || $hostname; my $host1 = shift || $hostname1; my $port = shift || $portnumber; my $port1 = shift || $portnumber1; my $proto = getprotobyname('tcp'); my $iaddr = inet_aton($host); my $iaddr1 = inet_aton($host1); my $paddr = sockaddr_in($port, $iaddr); my $paddr1 = sockaddr_in($port1, $iaddr1); socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; #for casino.sbobet.com eval { local $SIG{ALRM} = sub { die "timeout" }; alarm($timeout); connect(SOCKET, $paddr) || error(); alarm(0); }; if ($^P) { close SOCKET || die "close: $!"; print OUTFILE "$hostname is NOT listening on tcp port $portnumber.\n"; } else { close SOCKET || die "close: $!"; print OUTFILE "$hostname is listening on tcp port $portnumber."; my ($t02, $t12, $startTime2); $startTime2 = gettimeofday(); connect(SOCK, $paddr); $t02 = gettimeofday() - $startTime2; close (SOCK); $t02 = gettimeofday() - $startTime2, printf OUTFILE (" avg:%.8f", $t02); print OUTFILE ("ms\n"); } socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; #for casino1.sbobet.com eval { local $SIG{ALRM} = sub { die "timeout" }; alarm($timeout); connect(SOCKET, $paddr1) || error(); alarm(0); }; if ($ARGV) { close SOCKET || die "close: $!"; print OUTFILE "$hostname1 is NOT listening on tcp port $portnumber1.\n"; } else { close SOCKET || die "close: $!"; print OUTFILE "$hostname1 is listening on tcp port $portnumber1."; my ($t02, $t12, $startTime2); $startTime2 = gettimeofday(); connect(SOCK, $paddr1); $t02 = gettimeofday() - $startTime2; close (SOCK); $t02 = gettimeofday() - $startTime2, printf OUTFILE (" avg:%.8f", $t02); print OUTFILE ("ms"); }