]> git.armaanb.net Git - bin.git/blob - crontab-argh.c
xsel: new script
[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
3    -r" to "crontab -ri", but this isn't POSIX. */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 int
10 main(int argc, char *argv[]) {
11     char arg[255] = "crontab ";
12
13     for (int i = 1; i < argc; i++) {
14         strcat(arg, strcat(argv[i], " "));
15     }
16
17     if (strstr(arg, "-r") != NULL) {
18         printf("%s", "Delete user's crontab? [yes/no]: ");
19         char inp[255];
20         int ret;
21         while (1) {
22             ret = scanf("%s", inp);
23             if (ret == EOF)
24                 continue;
25             else if (strcmp(inp, "no") == 0)
26                 exit(0);
27             else if (strcmp(inp, "yes") == 0)
28                 break;
29             else
30                 printf("%s", "Please answer yes or no. [yes/no]: ");
31         }
32     }
33     system(arg);
34 }