我写了一个 letsencrypt 的自动续期脚本,手动是可以执行的 但是使用 crontab 执行不成功。 请问这是怎么回事?? 这是 脚本
cd /root/letsencrypt/ ./letsencrypt-auto certonly --webroot --webroot-path /usr/local/nginx/html -d hanyang.me -d www.hanyang.me --agree-tos --email [email protected] --renew-by-default cd /usr/local/nginx/sbin/ ./nginx -s reload
这是 crontab
40 12 7 * * sh /root/renew.sh
![]() | 1 Eleutherios 2016-12-07 16:20:32 +08:00 我猜: /bin/sh |
![]() | 2 hanyang OP @Eleutherios 需要在脚本前面加上 #!/bin/sh 吗 |
![]() | 3 cxh116 2016-12-07 16:23:19 +08:00 |
![]() | 4 KCheshireCat 2016-12-07 16:23:57 +08:00 试试取消掉目录切换,都用绝对路径 /root/letsencrypt/letsencrypt-auto ..... 比如这样 |
![]() | 5 Eleutherios 2016-12-07 16:24:03 +08:00 |
![]() | 7 hanyang OP @Eleutherios 我加了 可是还是不行。。。 |
![]() | 9 aleen42 2016-12-07 16:27:23 +08:00 修改 rsyslog sudo vim /etc/rsyslog.d/50-default.conf cron.* /var/log/cron.log #将 cron 前面的注释符去掉 重启 rsyslog sudo service rsyslog restart 查看 crontab 日志 less /var/log/cron.log crontab 问题定位 查看日志 /var/log/cron.log 和 /var/mail/$user 然后把时间调一下,看一下日志输出啥来着 |
![]() | 10 hanyang OP @cxh116 报这个错: An unexpected error occurred: Bug in pythondialog: expected an empty output from u'infobox', but got: u'Error opening terminal: unknown.\n'Please see the logfile 'certbot.log' for more details. |
11 kuretru 2016-12-07 16:33:14 +08:00 via iPhone 直接 certbot renew 就可以了 |
![]() | 12 vincentxue 2016-12-07 16:34:07 +08:00 |
![]() | 14 hanyang OP @cxh116 我用 git bash 登陆的 是 login shell 吧 ?执行后报这个错了: mesg: ttyname failed: Inappropriate ioctl for device An unexpected error occurred: Bug in pythondialog: expected an empty output from u'infobox', but got: u'Error opening terminal: unknown.\n'Please see the logfile 'certbot.log' for more details. |
![]() | 15 hanyang OP 谢谢大家的回复 我在 github 找到了[原因]( https://github.com/certbot/certbot/issues/1154) |
![]() | 16 RangerWolf 2016-12-07 17:33:20 +08:00 |
17 gqkkk 2016-12-07 17:42:36 +08:00 你这个是每月 7 号 12 点 40 分执行! 你是想要每月 7 日更新吗? |
![]() | 18 cxh116 2016-12-07 17:46:41 +08:00 |
19 yunfengjiang 2016-12-07 19:15:37 +08:00 建议使用绝对路径, 一般是环境变量问题。 |
![]() | 20 eoo 2016-12-07 22:29:01 +08:00 via Android 楼主把解决办法写一下 英文不会 |
![]() | 21 Infernalzero 2016-12-07 22:45:06 +08:00 40 12 7 * * . /etc/bashrc;/bin/bash /root/renew.sh |
![]() | 22 xiuc001 2016-12-07 22:49:30 +08:00 via iPhone 执行的时候报错会执行失败的,但是看上去像没执行一样 |
23 TaMud 2016-12-08 01:30:40 +08:00 SHELL=/bin/bash PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin 指令,脚本内指令,全部用绝对路径 |
24 TaMud 2016-12-08 01:31:04 +08:00 crontab -e 增加 SHELL=/bin/bash PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin 在最顶端 |
![]() | 25 justyy 2016-12-08 07:14:11 +08:00 很久之前写的一个工具 https://helloacm.com/crontab-generator/ |