From f5e388528bd8f1b6ca10a43c0f32f3fd1d3dfabe Mon Sep 17 00:00:00 2001 From: Nathan Straz Date: Thu, 1 Oct 2009 10:58:42 -0400 Subject: Add quiet option, document exit status --- btimec.1 | 8 +++++++- btimec.c | 15 +++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/btimec.1 b/btimec.1 index 1e67389..f661498 100644 --- a/btimec.1 +++ b/btimec.1 @@ -2,7 +2,7 @@ .SH NAME btimec \- Get the boot time of a host from btimed(8). .SH SYNOPSIS -\fBbtimec\fR [-\fBr\fR] \fIhost\fR [\fIhost\fR ...] +\fBbtimec\fR [-\fBqr\fR] \fIhost\fR [\fIhost\fR ...] .SH DESCRIPTION .B Btimec connects to btimed(8) on the specified \fIhost\fR to determine the time the @@ -11,7 +11,13 @@ output. If multiple hosts are listed, the value for each host is printed on a separate line. .SH OPTIONS .TP +.B \-q +Don't print the boot time. +.TP .B \-r Print the boot time in a human readable form. + +.SH EXIT STATUS +Success if the host returns a boot time, failure otherwise. .SH "SEE ALSO" btimed(8), qarsh(1) diff --git a/btimec.c b/btimec.c index f1d4518..2f791ff 100644 --- a/btimec.c +++ b/btimec.c @@ -29,21 +29,24 @@ #include "btime.h" -char usage[] = "USAGE: %s [-r] \n"; +char usage[] = "USAGE: %s [-qr] \n"; int main(int argc, char **argv) { unsigned int bt; char *btimedhost; - int readable = 0; + int readable = 1; int c; int ret = 0; - while ((c = getopt(argc, argv, "r")) != -1) { + while ((c = getopt(argc, argv, "qr")) != -1) { switch (c) { + case 'q': + readable = 0; + break; case 'r': - readable = 1; + readable = 2; break; default: fprintf(stderr, usage, argv[0]); @@ -59,11 +62,11 @@ main(int argc, char **argv) for ( ; optind < argc; optind++) { btimedhost = argv[optind]; bt = btime(btimedhost); - if (readable) { + if (readable == 2) { time_t tt = bt; time_t *ttp = &tt; printf("%s: %s", btimedhost, bt ? ctime(ttp) : "down\n"); - } else { + } else if (readable == 1) { printf("%s: %u\n", btimedhost, bt); } if (bt == 0) ret = 1; -- cgit