ubase/watch.c

51 lines
909 B
C
Raw Normal View History

2013-09-04 06:27:29 -04:00
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
2014-06-30 14:03:41 -04:00
#include <unistd.h>
2013-09-04 06:27:29 -04:00
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s [-t] [-n interval] command\n", argv0);
}
int
main(int argc, char *argv[])
{
char cmd[BUFSIZ];
int i, interval = 2;
ARGBEGIN {
case 't':
break;
case 'n':
/* Only whole seconds for now */
interval = estrtol(EARGF(usage()), 10);
break;
default:
usage();
} ARGEND;
if (argc < 1)
usage();
2014-08-25 14:14:34 -04:00
if (strlcpy(cmd, argv[0], sizeof(cmd)) >= sizeof(cmd))
eprintf("command too long\n");
2013-09-04 06:27:29 -04:00
for (i = 1; i < argc; i++) {
2014-08-25 14:14:34 -04:00
if (strlcat(cmd, " ", sizeof(cmd)) >= sizeof(cmd))
eprintf("command too long\n");
if (strlcat(cmd, argv[i], sizeof(cmd)) >= sizeof(cmd))
eprintf("command too long\n");
2013-09-04 06:27:29 -04:00
}
for (;;) {
printf("\x1b[2J\x1b[H"); /* clear */
2013-09-04 06:27:29 -04:00
fflush(NULL);
system(cmd);
sleep(interval);
}
2014-10-02 18:45:25 -04:00
return 0;
2013-09-04 06:27:29 -04:00
}