]> git.armaanb.net Git - bin.git/blob - crontab-argh.c
pubup: add variable expansion
[bin.git] / crontab-argh.c
1 /* Stops you from accidentally running crontab -r. alias this to crontab.
2          Alternatively, if you are on a GNU system, you can just alias "crontab -r" to
3          "crontab -ri", but this isn't POSIX. */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 int main(int argc, char *argv[]) {
10         char arg[255] = "crontab ";
11
12         for (int i = 1; i < argc; i++) {
13                 strcat(arg, strcat(argv[i], " "));
14         }
15
16         if (strstr(arg, "-r") != NULL) {
17                 printf("%s", "Delete user's crontab? [yes/no]: ");
18                 char inp[255];
19                 int ret;
20                 while (1) {
21                         ret = scanf("%s", inp);
22                         if (ret == EOF) continue;
23                         else if (strcmp(inp, "no") == 0) exit(0);
24                         else if (strcmp(inp, "yes") == 0) break;
25                         else printf("%s", "Please answer yes or no. [yes/no]: ");
26                 }
27         }
28         system(arg);
29 }