I was unable to replicate your results.
$ ping -ncl perlmonks.org ping: bad number of packets to transmit. $ ping -ncl www.perlmonks.org ping: bad number of packets to transmit. $
I found the c option to be relevant to what I'm shooting for now. I don't mean to be dismissive about the others, but I hardly understood them. In man ping, these are desribed as follows:
-n Numeric output only. No attempt will be made to lookup +symbolic names for host addresses. -c count Stop after sending count ECHO_REQUEST packets. With +deadline option, ping waits for count ECHO_REPLY packets, until t +he time‐ out expires. -l preload If preload is specified, ping sends that many packets n +ot wait‐ ing for reply. Only the super-user may select preload m +ore than 3.
I went with different options to see how it would dovetail with forked processes. I'll have more about ping at the end of this post, but I wanted to post the functions that would house it first, with the logic driven by an initial sftp->mkdir method call. First, I ssh to my site and put a plain file where I know the script is going to want to ask for a new directory:
(uiserver):u61210220:~/pmimage$ pwd >1.pitty2 (uiserver):u61210220:~/pmimage$ cat 1.pitty2 /kunden/homepages/9/d349337426/htdocs/pmimage (uiserver):u61210220:~/pmimage$
Then I run my normal html template with the new functions. Output then source:
Put file to server(y/n)?: y server dir is perlmonks parameter array is perlmonks Net::SFTP::Foreign=HASH(0x55825b47bcc8) C +ouldn't create remote directory: Failure error is Couldn't create remote directory: Failure
sub createDir { use 5.011; use Net::SFTP::Foreign; my ( $dirName, $sftp ) = @_; my $success = $sftp->mkdir($dirName) or handleDirCreateError( @_, $sftp->error ); return $success; } sub handleDirCreateError { use 5.011; use Net::SFTP::Foreign; use Net::SFTP::Foreign::Constants qw(:error); my ( $dirName, $sftp, $error ) = @_; say "parameter array is @_"; say "error is $error"; return $error; }
The error's description is less than complete.
I'm trying to get the functionality described in https://metacpan.org/pod/Net::SFTP::Foreign::Constants but seem to be missing something, as my error message looks a lot different than the ones in that module. One hopes to catch salva's eye, but it's improbable this deep in my own shit.
Q1) How do I employ the constants in that module for this case?
I've folded together elementary forking and pinging, and I really don't get what I've unearthed. This is the source:
$ cat 6.fork.pl #!/usr/bin/perl -w use 5.011; my $start = time; if (fork() == 0) { # arm the alarm clock alarm(10); # create a child process that sleeps system("ping www.google.com >5.fork.txt"); exit(0); } say "relevant processes with pstree command:"; system("pstree -Apal $$"); while((my $pid = wait()) != -1) { say "$pid terminated" } system("cat 5.fork.txt"); say time-$start, " ? <-ten seconds elapsed from forked process" __END__ $
This was the first trial:
$ ./6.fork.pl relevant processes with pstree command: 6.fork.pl,6780 -w ./6.fork.pl |-6.fork.pl,6781 -w ./6.fork.pl | `-sh,6783 -c ping www.google.com >5.fork.txt `-pstree,6782 -Apal 6780 6781 terminated PING www.google.com(sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::200 +4)) 56 data bytes 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=1 ttl=54 time=30.6 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=3 ttl=54 time=147 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=4 ttl=54 time=16.3 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=5 ttl=54 time=137 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=6 ttl=54 time=123 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=7 ttl=54 time=20.5 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=8 ttl=54 time=20.7 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=9 ttl=54 time=20.3 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=10 ttl=54 time=24.2 ms 10 seconds elapsed instead of a year
This was as I expected it. The icmp_seq= went from 1 to 10. I expected the same output if run again and was wrong:
$ ./6.fork.pl relevant processes with pstree command: 6.fork.pl,6800 -w ./6.fork.pl |-6.fork.pl,6801 -w ./6.fork.pl | `-sh,6803 -c ping www.google.com >5.fork.txt | `-ping,6804 www.google.com `-pstree,6802 -Apal 6800 6801 terminated PING www.google.com(sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::200 +4)) 56 data bytes 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=1 ttl=54 time=141 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=2 ttl=54 time=17.8 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=3 ttl=54 time=33.0 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=4 ttl=54 time=31.7 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=5 ttl=54 time=28.0 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=6 ttl=54 time=34.9 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=7 ttl=54 time=25.0 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=8 ttl=54 time=19.7 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=9 ttl=54 time=18.2 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=10 ttl=54 time=39.5 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=144 ttl=54 time=18.5 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=145 ttl=54 time=271 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=146 ttl=54 time=346 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=147 ttl=54 time=35.9 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=148 ttl=54 time=205 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=149 ttl=54 time=42.1 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=150 ttl=54 time=168 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=151 ttl=54 time=20.5 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=152 ttl=54 time=377 ms 10? <-ten seconds elapsed from forked process
The icmp_seq= values go up to 152, and there is twice as much output. The third trial had these values all over the map:
$ ./6.fork.pl relevant processes with pstree command: 6.fork.pl,6839 -w ./6.fork.pl |-6.fork.pl,6840 -w ./6.fork.pl | `-sh,6842 -c ping www.google.com >5.fork.txt | `-ping,6843 www.google.com `-pstree,6841 -Apal 6839 6840 terminated PING www.google.com(sea30s02-in-x04.1e100.net (2607:f8b0:400a:803::200 +4)) 56 data bytes 64 bytes from sea30s02-in-x04.1e100.net (2607:f8b0:400a:803::2004): ic +mp_seq=1 ttl=54 time=33.4 ms 64 bytes from sea30s02-in-x04.1e100.net (2607:f8b0:400a:803::2004): ic +mp_seq=4 ttl=54 time=36.3 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=460 ttl=54 time=123 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=463 ttl=54 time=37.0 ms 64 bytes from sea15s07-in-x04.1e100.net (2607:f8b0:400a:800::2004): ic +mp_seq=466 ttl=54 time=18.1 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=605 ttl=54 time=44.4 ms 64 bytes from sea15s11-in-x04.1e100.net (2607:f8b0:400a:808::2004): ic +mp_seq=608 ttl=54 time=31.3 ms 10 ? <-ten seconds elapsed from forked process
Q2) What does icmp_seq=608 mean in this context?
Q3) With 30 seconds of pinging google, how much data was sent? How much of this type of activity can a person do without it being interpreted as an attack?
What really threw me for a loop is when I walked away from my laptop, came back later to it and find:
$ ping: sendmsg: Network is unreachable ping: sendmsg: Network is unreachable ping: sendmsg: Network is unreachable ...
They descended like ghosts, long after the programs were supposedly done executing, and twice.
After a couple of days of making mistakes, this seems like a good ping command to test whether one has internet connectivity:
$ ping -c 3 www.google.com PING www.google.com(sea15s12-in-x04.1e100.net (2607:f8b0:400a:809::200 +4)) 56 data bytes 64 bytes from sea15s12-in-x04.1e100.net (2607:f8b0:400a:809::2004): ic +mp_seq=1 ttl=54 time=17.0 ms 64 bytes from sea15s12-in-x04.1e100.net (2607:f8b0:400a:809::2004): ic +mp_seq=2 ttl=54 time=21.1 ms 64 bytes from sea15s12-in-x04.1e100.net (2607:f8b0:400a:809::2004): ic +mp_seq=3 ttl=54 time=19.0 ms --- www.google.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 17.096/19.092/21.126/1.649 ms
Q4) What could you regex for to decide that this were a success?
Finally, I didn't want to post before taking a whirl with hippo's suggestion of Net::Ping. Here's the source:
#!/usr/bin/perl -w use 5.011; use Net::Ping; my $start = time; if ( fork() == 0 ) { # arm the alarm clock alarm(5); my @sites = qw/www.google.com www.merrillpjensen.com www.perlmonks.o +rg/; for my $host (@sites) { my $p = Net::Ping->new(); print "$host is alive.\n" if $p->ping($host); $p->close(); } exit(0); } say "relevant processes with pstree command:"; system("pstree -Apal $$"); while ( ( my $pid = wait() ) != -1 ) { say "$pid terminated"; } #system("cat 7.fork.txt"); say time - $start, " ? seconds elapsed from forked process" __END__
The unimpressive output is:
relevant processes with pstree command: 7.fork.pl,27579 -w ./7.fork.pl |-7.fork.pl,27580 -w ./7.fork.pl `-pstree,27581 -Apal 27579 27580 terminated 5 ? seconds elapsed from forked process
The intent is to loop over a few sites and see if pinging is successful. I wonder what makes a site pingable like google, and how we might handle a ping sent to our own sites.
Anyways, long post, arrrggh...
Thank you for your comments,
In reply to Re^5: using online translation engines with perl (ping)
by Aldebaran
in thread using online translation engines with perl
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |