首页 > 解决方案 > 让 crontab 运行重建

问题描述

我正在构建一个脚本,它可以帮助我每天在我的 CMS 上更新新内容时重新构建静态站点。出于测试目的,我正在本地计算机上进行尝试。

名为 helloworld.sh 的脚本是

#!/bin/bash (cd /Projects/blog && gatsby build)

我已经将 crontab -e 编辑为

* * * * * /Projects/scripts/helloworld.sh

这使它每分钟运行一次,仅用于测试目的。但是,当我运行服务 cron 状态时,它不起作用并返回错误,未安装 MTA,丢弃输出。我查了一下,它是关于邮件输出的,据说它根本不应该影响脚本的作用。

Apr 30 23:05:01 unicornfinder CRON[12363]: (unicornfinder) CMD (/Projects/scripts/helloworld.sh)

Apr 30 23:05:01 unicornfinder CRON[12362]: (CRON) info (No MTA installed, discarding output)

我如何让这个脚本运行?谢谢!

标签: bashubuntucron

解决方案


When there's an error on cron jobs and job output is not redirected to a file, cron tries to send an email to the user which in your case fails because there's no MTA. Edit your crontab

* * * * * /Projects/scripts/helloworld.sh >> /tmp/file.log 2>&1


推荐阅读