Ubuntu

無法添加 cron 任務

  • July 27, 2022

我正在嘗試添加 cron 任務來更新我的 certbot 證書,但我似乎無法做到這一點。我使用了這個命令: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。

你只想跑crontab -e然後打Enter

然後您的 crontab 將出現在您的環境中配置的編輯器中。

然後,在編輯器中,您可以將該行添加到要添加的 crontab 中:

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

問題是您試圖合二為一。

引用自:https://serverfault.com/questions/1106696