*/
time_t cronnext(cron_db database,
time_t start, time_t end,
- char *include, char *exclude, int flags) {
+ char *include, char *exclude, char *command, int flags) {
time_t closest, next;
user *u;
entry *e;
if (flags & CRONTABS)
printcrontab(u);
- for (e = u->crontab; e; e = e->next)
+ for (e = u->crontab; e; e = e->next) {
+ if (command && strstr(e->cmd, command) == NULL)
+ continue;
for (next = nextmatch(e, start, end);
next <= end;
next = nextmatch(e, next + 60, end)) {
if (! (flags & ALLJOBS))
break;
}
+ }
}
return closest;
fprintf(stderr, " -a examine installed crontabs even if files are given\n");
fprintf(stderr, " -t time start from this time (seconds since epoch)\n");
fprintf(stderr, " -q time end check at this time (seconds since epoch)\n");
+ fprintf(stderr, " -j cmd only check jobs that contain cmd as a substring\n");
fprintf(stderr, " -l print next jobs to be executed\n");
fprintf(stderr, " -c print next execution of each job\n");
fprintf(stderr, " -f print all jobs executed in the given interval\n");
*/
int main(int argn, char *argv[]) {
int opt;
- char *include, *exclude;
+ char *include, *exclude, *command;
int flags;
time_t start, next, end = 0;
int endtime, printjobs;
include = NULL;
exclude = NULL;
+ command = NULL;
flags = SYSTEM;
endtime = 0;
printjobs = 0;
start = time(NULL) / 60 * 60;
- while (-1 != (opt = getopt(argn, argv, "i:e:ast:q:lcfhV"))) {
+ while (-1 != (opt = getopt(argn, argv, "i:e:ast:q:j:lcfhV"))) {
switch (opt) {
case 'i':
include = optarg;
end = atoi(optarg) / 60 * 60;
endtime = 1;
break;
+ case 'j':
+ command = optarg;
+ break;
case 'l':
printjobs = 1;
break;
db = database(installed || argv[optind] == NULL, argv + optind);
/* find time of next scheduled command */
- next = cronnext(db, start, end, include, exclude, flags);
+ next = cronnext(db, start, end, include, exclude, command, flags);
/* print time */
if (next == -1)
/* print next jobs */
if (printjobs) {
printf("nextjobs:\n");
- cronnext(db, next, next, include, exclude, (flags & SYSTEM) | ENTRIES);
+ cronnext(db, next, next, include, exclude, command, (flags & SYSTEM) | ENTRIES);
}
return EXIT_SUCCESS;