diff options
author | Nate Straz <nstraz@redhat.com> | 2006-02-13 16:31:52 +0000 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2008-09-23 09:37:46 -0400 |
commit | b4f6606bb43e42fa741565138cb9049c2081030a (patch) | |
tree | e5035a2d990911e48f093646eddf7e3fa305fc5a | |
parent | 1fec42b3baed7df17ca1216a1d6249fe423c3f78 (diff) | |
download | qarsh-b4f6606bb43e42fa741565138cb9049c2081030a.tar.gz qarsh-b4f6606bb43e42fa741565138cb9049c2081030a.tar.xz qarsh-b4f6606bb43e42fa741565138cb9049c2081030a.zip |
Add an option, -r, to get a readable boot time
Convert to getopt
Allow multiple hosts on the command line
-rw-r--r-- | btimec.c | 37 |
1 files changed, 30 insertions, 7 deletions
@@ -6,23 +6,46 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> +#include <time.h> #include "btime.h" +char usage[] = "USAGE: %s [-r] <host>\n"; + int main(int argc, char **argv) { unsigned int bt; char *btimedhost; + int readable = 0; + int c; - if (argc != 2) { - fprintf(stderr, "USAGE: %s <host>\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); } |