Sometimes I want ping to be quiet. Not quiet in the "only show me headers" way that the original author thought was cute, but in the "don't show me anything" way, so cron doesn't spam me with useless crap.
So, in honor of that, here is a patch to add -Q to ping and ping6. OK? Index: sbin/ping/ping.8 =================================================================== RCS file: /cvs/openbsd/src/sbin/ping/ping.8,v retrieving revision 1.45 diff -u -p -r1.45 ping.8 --- sbin/ping/ping.8 3 Jul 2010 04:44:51 -0000 1.45 +++ sbin/ping/ping.8 5 Apr 2011 21:23:29 -0000 @@ -39,7 +39,7 @@ .Sh SYNOPSIS .Nm ping .Bk -words -.Op Fl DdEefLnqRrv +.Op Fl DdEefLnQqRrv .Op Fl c Ar count .Op Fl I Ar ifaddr .Op Fl i Ar wait @@ -155,6 +155,9 @@ will cause the sent packet to be filled Quiet output. Nothing is displayed except the summary lines at startup time and when finished. +.It Fl Q +Very quiet output. +Nothing is displayed at all. .It Fl R Record route. Includes the Index: sbin/ping/ping.c =================================================================== RCS file: /cvs/openbsd/src/sbin/ping/ping.c,v retrieving revision 1.88 diff -u -p -r1.88 ping.c --- sbin/ping/ping.c 3 Jul 2010 04:44:51 -0000 1.88 +++ sbin/ping/ping.c 5 Apr 2011 21:12:12 -0000 @@ -108,6 +108,7 @@ int options; #define F_SO_JUMBO 0x1000 #define F_AUD_RECV 0x2000 #define F_AUD_MISS 0x4000 +#define F_REALLY_QUIET 0x8000 /* multicast options */ int moptions; @@ -201,7 +202,7 @@ main(int argc, char *argv[]) preload = 0; datap = &outpack[8 + sizeof(struct tvi)]; while ((ch = getopt(argc, argv, - "DEI:LRS:c:defi:jl:np:qrs:T:t:V:vw:")) != -1) + "DEI:LRS:c:defi:jl:np:Qqrs:T:t:V:vw:")) != -1) switch(ch) { case 'c': npackets = (unsigned long)strtonum(optarg, 0, @@ -277,7 +278,10 @@ main(int argc, char *argv[]) case 'p': /* fill buffer with user pattern */ options |= F_PINGFILLED; fill((char *)datap, optarg); - break; + break; + case 'Q': + options |= F_REALLY_QUIET; + /* FALLTHROUGH */ case 'q': options |= F_QUIET; break; @@ -487,12 +491,14 @@ main(int argc, char *argv[]) warnx("Could only allocate a receive buffer of %i bytes (default %i)", bufspace, IP_MAXPACKET); - if (to->sin_family == AF_INET) - (void)printf("PING %s (%s): %d data bytes\n", hostname, - inet_ntoa(*(struct in_addr *)&to->sin_addr.s_addr), - datalen); - else - (void)printf("PING %s: %d data bytes\n", hostname, datalen); + if (!(options & F_REALLY_QUIET)) { + if (to->sin_family == AF_INET) + (void)printf("PING %s (%s): %d data bytes\n", hostname, + inet_ntoa(*(struct in_addr *)&to->sin_addr.s_addr), + datalen); + else + (void)printf("PING %s: %d data bytes\n", hostname, datalen); + } (void)signal(SIGINT, finish); (void)signal(SIGALRM, catcher); @@ -1008,7 +1014,9 @@ finish(int signo) { (void)signal(SIGINT, SIG_IGN); - summary(1, signo); + if (!(options & F_REALLY_QUIET)) + summary(1, signo); + if (signo) _exit(nreceived ? 0 : 1); else @@ -1363,7 +1371,7 @@ void usage(void) { (void)fprintf(stderr, - "usage: ping [-DdEefLnqRrv] [-c count] [-I ifaddr] [-i wait]\n" + "usage: ping [-DdEefLnQqRrv] [-c count] [-I ifaddr] [-i wait]\n" "\t[-l preload] [-p pattern] [-s packetsize] [-T tos] [-t ttl]\n" "\t[-V rtable] [-w maxwait] host\n"); exit(1); Index: sbin/ping6/ping6.8 =================================================================== RCS file: /cvs/openbsd/src/sbin/ping6/ping6.8,v retrieving revision 1.42 diff -u -p -r1.42 ping6.8 --- sbin/ping6/ping6.8 26 Jun 2010 18:30:03 -0000 1.42 +++ sbin/ping6/ping6.8 6 Apr 2011 04:52:29 -0000 @@ -36,7 +36,7 @@ .Nd send ICMPv6 ECHO_REQUEST packets to network hosts .Sh SYNOPSIS .Nm ping6 -.Op Fl dEefHmNnqtvWw +.Op Fl dEefHmNnQqtvWw .Op Fl a Ar addrtype .Op Fl b Ar bufsiz .Op Fl c Ar count @@ -213,6 +213,9 @@ ones. Quiet output. Nothing is displayed except the summary lines at startup time and when finished. +.It Fl Q +Really quiet output. +Nothing is displayed at all. .\".It Fl R .\"Make the kernel believe that the target .\".Ar host Index: sbin/ping6/ping6.c =================================================================== RCS file: /cvs/openbsd/src/sbin/ping6/ping6.c,v retrieving revision 1.81 diff -u -p -r1.81 ping6.c --- sbin/ping6/ping6.c 3 Mar 2011 00:30:31 -0000 1.81 +++ sbin/ping6/ping6.c 6 Apr 2011 05:00:32 -0000 @@ -154,6 +154,7 @@ struct tv32 { #define F_NOMINMTU 0x100000 #define F_AUD_RECV 0x200000 #define F_AUD_MISS 0x400000 +#define F_REALLY_QUIET 0x800000 #define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES) u_int options; @@ -279,7 +280,7 @@ main(int argc, char *argv[]) preload = 0; datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN]; while ((ch = getopt(argc, argv, - "a:b:c:dEefHg:h:I:i:l:mnNp:qRS:s:tvwW")) != -1) { + "a:b:c:dEefHg:h:I:i:l:mnNp:QqRS:s:tvwW")) != -1) { switch (ch) { case 'a': { @@ -424,6 +425,9 @@ main(int argc, char *argv[]) options |= F_PINGFILLED; fill((char *)datap, optarg); break; + case 'Q': + options |= F_REALLY_QUIET; + /* FALLTHROUGH */ case 'q': options |= F_QUIET; break; @@ -849,10 +853,14 @@ main(int argc, char *argv[]) (socklen_t)sizeof(optval)) < 0) warn("setsockopt(IPV6_RECVHOPLIMIT)"); /* XXX err? */ - printf("PING6(%lu=40+8+%lu bytes) ", (unsigned long)(40 + pingerlen()), - (unsigned long)(pingerlen() - 8)); - printf("%s --> ", pr_addr((struct sockaddr *)&src, sizeof(src))); - printf("%s\n", pr_addr((struct sockaddr *)&dst, sizeof(dst))); + if (!(options & F_REALLY_QUIET)) { + printf("PING6(%lu=40+8+%lu bytes) ", + (unsigned long)(40 + pingerlen()), + (unsigned long)(pingerlen() - 8)); + printf("%s --> ", + pr_addr((struct sockaddr *)&src, sizeof(src))); + printf("%s\n", pr_addr((struct sockaddr *)&dst, sizeof(dst))); + } while (preload--) /* Fire off them quickies. */ (void)pinger(); @@ -897,7 +905,8 @@ main(int argc, char *argv[]) } #ifdef SIGINFO if (seeninfo) { - summary(0); + if (!(options & F_REALLY_QUIET)) + summary(0); seeninfo = 0; continue; } @@ -967,7 +977,8 @@ main(int argc, char *argv[]) } } - summary(0); + if (!(options & F_REALLY_QUIET)) + summary(0); exit(nreceived == 0); } @@ -1941,7 +1952,8 @@ tvsub(struct timeval *out, struct timeva void onint(int signo) { - summary(signo); + if (!(options & F_REALLY_QUIET)) + summary(signo); (void)signal(SIGINT, SIG_DFL); (void)kill(getpid(), SIGINT); -- If only I could be respected without having to be respectable.