bash - 让 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)
我如何让这个脚本运行?谢谢!
解决方案
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
推荐阅读
- multithreading - 定时器不能从另一个线程 Qt 停止
- c++ - 大数组和的优化(多线程)
- sql-server - 如何使用别名更正查询
- python - 使用 Holoviews,如何设置标题?
- r - 一起布置列表ggplot时保持绘制的高度固定
- html - 如何用垂直折线分割页面背景?
- ruby - 对 Chef 变量有疑问,似乎无法让变量工作
- database - Updating an Aho-Corasick trie in the face of inserts and deletes
- python - 使用Python在excel中查找连续数字组
- java - 使用 MultiValueMap 作为参数测试端点