// // Execute the given command every N seconds. // #include #include #include #include void Execute(char *Command, ...); main (int argc, char *argv[]) { int Seconds; char *Command; Seconds = 60; if (argc > 1) { Seconds = atoi(argv[1]); } if (argc > 2) { Command = argv[2]; } if (argc != 3) { fprintf(stderr, "Usage: every [seconds] [command...]\n"); fprintf(stderr, "- use quotes around command and arguments if necessary\n"); exit(1); } while (1) { time_t t; time (&t); printf("%.24s: ", ctime(&t)); Execute(Command); _sleep(Seconds * 1000); } } void Execute (char *Command, ...) { char Buffer[100]; va_list vap; va_start(vap, Command); vsprintf(Buffer, Command, vap); va_end(vap); printf("*** %s\n", Buffer); system(Buffer); return; }