summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNate Straz <nstraz@redhat.com>2006-02-13 16:31:52 +0000
committerNathan Straz <nstraz@redhat.com>2008-09-23 09:37:46 -0400
commitb4f6606bb43e42fa741565138cb9049c2081030a (patch)
treee5035a2d990911e48f093646eddf7e3fa305fc5a
parent1fec42b3baed7df17ca1216a1d6249fe423c3f78 (diff)
downloadqarsh-b4f6606bb43e42fa741565138cb9049c2081030a.zip
qarsh-b4f6606bb43e42fa741565138cb9049c2081030a.tar.gz
qarsh-b4f6606bb43e42fa741565138cb9049c2081030a.tar.xz
Add an option, -r, to get a readable boot time
Convert to getopt Allow multiple hosts on the command line
-rw-r--r--btimec.c37
1 files 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 <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);
}