From b4f6606bb43e42fa741565138cb9049c2081030a Mon Sep 17 00:00:00 2001 From: Nate Straz Date: Mon, 13 Feb 2006 16:31:52 +0000 Subject: Add an option, -r, to get a readable boot time Convert to getopt Allow multiple hosts on the command line --- btimec.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/btimec.c b/btimec.c index 02c29bc..bea87bb 100644 --- a/btimec.c +++ b/btimec.c @@ -6,23 +6,46 @@ #include #include +#include +#include #include "btime.h" +char usage[] = "USAGE: %s [-r] \n"; + int main(int argc, char **argv) { unsigned int bt; char *btimedhost; + int readable = 0; + int c; - if (argc != 2) { - fprintf(stderr, "USAGE: %s \n", argv[0]); - exit(2); + while ((c = getopt(argc, argv, "r")) != -1) { + switch (c) { + case 'r': + readable = 1; + break; + default: + fprintf(stderr, usage, argv[0]); + exit(2); + } } - btimedhost = argv[1]; - bt = btime(btimedhost); - printf("%s: %u\n", btimedhost, bt); - + if (optind >= argc) { + fprintf(stderr, usage, argv[0]); + exit(2); + } + for ( ; optind < argc; optind++) { + btimedhost = argv[optind]; + bt = btime(btimedhost); + if (readable) { + time_t tt = bt; + time_t *ttp = &tt; + printf("%s: %s", btimedhost, bt ? ctime(ttp) : "down\n"); + } else { + printf("%s: %u\n", btimedhost, bt); + } + } exit(0); } -- cgit