无法添加 cron 任务

无法添加 cron 任务

我正在尝试添加 cron 任务,以便在每次证书即将过期时更新证书,但似乎无法做到这一点。我使用了以下命令:crontab -e 0 12 * * * /usr/bin/certbot renew -quiet

crontab: invalid option -- 'q'
crontab: usage error: unrecognized option
usage:  crontab [-u user] file
        crontab [ -u user ] [ -i ] { -e | -l | -r }
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

还尝试了这个:rontab -e 0 12 * * * /usr/bin/certbot renew --quiet 并得到:

crontab: invalid option -- '-'
crontab: usage error: unrecognized option
usage:  crontab [-u user] file
        crontab [ -u user ] [ -i ] { -e | -l | -r }
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

这:crontab -e 0 12 * * * /usr/bin/certbot renew -q

crontab: invalid option -- 'q'
crontab: usage error: unrecognized option
usage:  crontab [-u user] file
        crontab [ -u user ] [ -i ] { -e | -l | -r }
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

这:crontab -e 0 12 * * * -q /usr/bin/certbot renew

crontab: invalid option -- 'q'
crontab: usage error: unrecognized option
usage:  crontab [-u user] file
        crontab [ -u user ] [ -i ] { -e | -l | -r }
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

这:crontab -e 0 12 * * * --quiet /usr/bin/certbot renew

crontab: invalid option -- '-'
crontab: usage error: unrecognized option
usage:  crontab [-u user] file
        crontab [ -u user ] [ -i ] { -e | -l | -r }
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

这:crontab -e 0 12 * * * /usr/bin/certbot renew

crontab: usage error: no arguments permitted after this option
usage:  crontab [-u user] file
        crontab [ -u user ] [ -i ] { -e | -l | -r }
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

我也尝试crontab -e 43 6 * * * certbot renew --post-hook "systemctl reload nginx"这个答案,但它抛出了:

crontab: invalid option -- '-'
crontab: usage error: unrecognized option
usage:  crontab [-u user] file
        crontab [ -u user ] [ -i ] { -e | -l | -r }
                (default operation is replace, per 1003.2)
        -e      (edit user's crontab)
        -l      (list user's crontab)
        -r      (delete user's crontab)
        -i      (prompt before deleting user's crontab)

我不知道我还能做什么。我使用 Ubuntu 20.04。

答案1

你只想跑crontab -e然后打Enter

然后您的 crontab 将出现在您的环境中配置的编辑器中。

在编辑器中,您可以然后将要添加的行添加到 crontab 中:

0 12 * * * /usr/bin/certbot renew -quiet

问题在于您试图一次性完成两个步骤。

相关内容