Add a 'force' option for non-interactive crontab removal
Add a '-f' option to force crontab '-r' to be non-interactive. Submitted by: Sam Gwydir <sam at samgwydir.com> Reviewed by: me, wblock (previous version) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D8815
This commit is contained in:
parent
8a73c85db3
commit
d21656dcab
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=310329
@ -17,7 +17,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd May 13, 2010
|
.Dd December 20, 2016
|
||||||
.Dt CRONTAB 1
|
.Dt CRONTAB 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -31,7 +31,8 @@
|
|||||||
.Op Fl u Ar user
|
.Op Fl u Ar user
|
||||||
{
|
{
|
||||||
.Fl l |
|
.Fl l |
|
||||||
.Fl r |
|
.Fl r Op Fl f
|
||||||
|
|
|
||||||
.Fl e
|
.Fl e
|
||||||
}
|
}
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
@ -97,6 +98,11 @@ option for safety's sake.
|
|||||||
Display the current crontab on standard output.
|
Display the current crontab on standard output.
|
||||||
.It Fl r
|
.It Fl r
|
||||||
Remove the current crontab.
|
Remove the current crontab.
|
||||||
|
By default the
|
||||||
|
.Fl r
|
||||||
|
option prompts for confirmation, adding the
|
||||||
|
.Fl f
|
||||||
|
option will attempt to remove the current crontab without confirmation.
|
||||||
.It Fl e
|
.It Fl e
|
||||||
Edit the current crontab using the editor specified by
|
Edit the current crontab using the editor specified by
|
||||||
the
|
the
|
||||||
|
@ -63,6 +63,7 @@ static char Filename[MAX_FNAME];
|
|||||||
static FILE *NewCrontab;
|
static FILE *NewCrontab;
|
||||||
static int CheckErrorCount;
|
static int CheckErrorCount;
|
||||||
static enum opt_t Option;
|
static enum opt_t Option;
|
||||||
|
static int fflag;
|
||||||
static struct passwd *pw;
|
static struct passwd *pw;
|
||||||
static void list_cmd(void),
|
static void list_cmd(void),
|
||||||
delete_cmd(void),
|
delete_cmd(void),
|
||||||
@ -79,7 +80,7 @@ usage(char *msg)
|
|||||||
fprintf(stderr, "crontab: usage error: %s\n", msg);
|
fprintf(stderr, "crontab: usage error: %s\n", msg);
|
||||||
fprintf(stderr, "%s\n%s\n",
|
fprintf(stderr, "%s\n%s\n",
|
||||||
"usage: crontab [-u user] file",
|
"usage: crontab [-u user] file",
|
||||||
" crontab [-u user] { -e | -l | -r }");
|
" crontab [-u user] { -l | -r [-f] | -e }");
|
||||||
exit(ERROR_EXIT);
|
exit(ERROR_EXIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ parse_args(argc, argv)
|
|||||||
strcpy(RealUser, User);
|
strcpy(RealUser, User);
|
||||||
Filename[0] = '\0';
|
Filename[0] = '\0';
|
||||||
Option = opt_unknown;
|
Option = opt_unknown;
|
||||||
while ((argch = getopt(argc, argv, "u:lerx:")) != -1) {
|
while ((argch = getopt(argc, argv, "u:lerx:f")) != -1) {
|
||||||
switch (argch) {
|
switch (argch) {
|
||||||
case 'x':
|
case 'x':
|
||||||
if (!set_debug_flags(optarg))
|
if (!set_debug_flags(optarg))
|
||||||
@ -172,6 +173,9 @@ parse_args(argc, argv)
|
|||||||
usage("only one operation permitted");
|
usage("only one operation permitted");
|
||||||
Option = opt_edit;
|
Option = opt_edit;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
fflag = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage("unrecognized option");
|
usage("unrecognized option");
|
||||||
}
|
}
|
||||||
@ -282,7 +286,7 @@ delete_cmd() {
|
|||||||
char n[MAX_FNAME];
|
char n[MAX_FNAME];
|
||||||
int ch, first;
|
int ch, first;
|
||||||
|
|
||||||
if (isatty(STDIN_FILENO)) {
|
if (!fflag && isatty(STDIN_FILENO)) {
|
||||||
(void)fprintf(stderr, "remove crontab for %s? ", User);
|
(void)fprintf(stderr, "remove crontab for %s? ", User);
|
||||||
first = ch = getchar();
|
first = ch = getchar();
|
||||||
while (ch != '\n' && ch != EOF)
|
while (ch != '\n' && ch != EOF)
|
||||||
|
Loading…
Reference in New Issue
Block a user