Raspberry Pi crontab not work bug All In One
1.How to fix the bug that there is no signal when the Raspberry Pi is connected to a monitor with an HDMI cable All In One2.Raspberry Pi command line tools vcgencmd All In One3.Python rpi_ws281x library All In One4.Adafruit CircuitPython NeoPixel All In One5.How to fix the problem that Raspberry Pi cannot use the root user for SSH login All In One6.How to modify the hostname and username and password of Raspberry Pi All In One7.树莓派 4B 核心电子元器件图解 All In One8.Linux install vim errors All In One9.How to boot the Raspberry Pi system from a USB Mass Storage Device All In One10.How to Control an External USB Web Camera Using a Raspberry Pi All In One11.ARM Cortex-A72 CPU All In One12.Linux shutdown & reboot & poweroff All In One13.软路由 & 旁路由 All In One14.How to change the default Python2 to Python3 on Linux All In One15.Raspberry Pi 4 Model B Product Information Portal All In One16.use SSH to connect to Raspberry Pi methods All In One17.国产单片机开发板 All In One18.How to use Raspberry Pi scan bluetooth devices All In One19.How to use the Raspberry Pi and Python to control a DHT11 wet and temperate module All In One20.How to use the Raspberry Pi and Python to control a buzzer All In One21.gpiozero API All In One22.RPi.GPIO API All In One23.Node.js & Raspberry Pi & WS2812B RGB LEDs strip All In One24.Raspberry Pi 3 Model B and Raspberry Pi 3 Model B+ and and Raspberry Pi 4 Model B All In One25.How to use Linux command or Python code get Raspberry PI's Temperature All In One26.How to connect to multiple SSD1306 OLED Displays using Raspberry Pi GPIO I2C PIN All In One27.Raspberry Pi & 0.96 inch SSD1306 OLED display All In One28.WS2812B RGB LED 灯带外接电源所需要的电压计算公式 All In One29.Raspberry Pi GPIO pins All In One30.如何使用蓝牙控制树莓派 All In One31. Raspberry Pi & Experience AI All In One32.如何修复树莓派在更换了一个 SD 系统卡后,无法使用 SSH 登录问题 All In One33.How to use the Raspberry Pi to study the Linux kernel source code All In One34.Raspberry Pi 设置开机登录后自启动脚本 All In One35.How to use SSH to access the Raspberry Pi without know the Wi-Fi IP address All In One36.Raspberry Pi Code Editor All In One37.Linux copy from pipe command All In One38.how to use crontab to send an email on Linux All In One39.macOS Terminal & Raspberry Pi client_loop: send disconnect: Broken pipe All In One
40.Raspberry Pi crontab not work bug All In One
41.Raspberry Pi GPIO 针脚图解教程 All In One42.how to get Raspberry Pi System Information All In One43.2023 最新的如何树莓派上安装中文输入法和设置中文语言环境教程 All In One44.Linux change archive mirror All In One45.How to publish a Linux package to mirror All In One46.Raspberry Pi 3B won't turn on after being powered on All In One47.Raspberry Pi Debug Probe All In One48.How to find the "usbmodem" of Raspberry Pi Pico on macOS All In One49.How to check the USB devices connected to Linux by using Terminal All In One50.Raspberry Pi Imager All In One51.use macOS terminal can not install MicroPython on Raspberry Pi Pico bug All In One52.Raspberry Pi Pico All In One53.macOS 如何通过 SSH 访问树莓派 All In One54.面包板使用教程 All In One55.Raspberry Pi Pico & MicroPython All In One56.Raspberry Pi & Python & GPIO All In One57.Raspberry Pi Remote Access All In One58.Raspberry Pi 4 B 8G All In One59.How to use macOS to connect to Raspberry Pi without the monitor All In One60.Linux 关机命令 All In One61.Raspberry Pi 5 All In One62.TensorFlow Lite & Raspberry Pi All In One63.how to install GitLab on Raspberry Pi OS 64.Raspberry Pi & GPIO All In One65.Raspberry Pi 电路图模拟器 All In One66.树莓派 4B 入门教程 All In One67.如何在树莓派上搭建 gitlab 服务 All In One68.Raspberry Pi & Node.js & WebSockets & IM69.Raspberry Pi & Raspberry Pi 4 All In One70.IoT & Raspberry Pi71.NMAP 使用教程 All In One72.如何使用 config.txt 配置 Raspberry Pi 3 的各种信息!73.如何在没有显示器的情况下查看 Raspberry Pi 3 的 IP 地址信息 All In One74.How To Install Linux & Nginx & MySQL & PHP (LEMP) stack on Raspberry Pi 3 All In One75.如何启用树莓派的硬件看门狗功能,让它在系统宕机时可以自动重新开机 All In One76.如何在 Raspberry Pi 树莓派上安装浏览器的详细教程 All In One77.树莓派(raspberry pi 3) 中文界面支持的设置,安装中文环境,中文输入法 All In One78.2016 最新的树莓派3 上手评测图解教程新手必看 All In OneRaspberry Pi crontab not work bug All In One
Raspberry Pi crontab 不执行 bug
bug ❌
# 用户 crontab (pi)
pi@raspberrypi:~/Desktop $ crontab -e
pi@raspberrypi:~/Desktop $ crontab -l
# 用户 crontab (root)
pi@raspberrypi:~/Desktop $ sudo crontab -e
pi@raspberrypi:~/Desktop $ sudo crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
- 用户
crontab
(⚠️ 没有用户字段 pi )
# 自动化执行脚本 ✅
# 每隔 3 分钟执行一次
# 分钟 小时 天 月 周
#3 * * * * pi sh ./Desktop/gpio.py
# user python 参数
# 3 * * * * pi python ./gpio.py 3
# 绝对路径 python ✅
# 二合一输出 log 🚀
3 * * * * /usr/bin/python /home/pi/Desktop/gpio.py 3 > /home/pi/Desktop/gpio.log.txt 2>&1
# 用户 crontab(⚠️ 没有用户字段 pi )
# 3 * * * * pi /usr/bin/python /home/pi/Desktop/gpio.py 3
- 系统 crontab
/etc/crontab
# /etc/crontab 系统 crontab ✅
# user python 参数
# 3 * * * * pi python ./gpio.py 3
# 绝对路径 python ✅
# 二合一输出 log 🚀
3 * * * * pi /usr/bin/python /home/pi/Desktop/gpio.py 3 > /home/pi/Desktop/gpio.log.txt 2>&1
问题分析
# 开启 cron log ✅
$ sudo vim /etc/rsyslog.conf
# cron.* /var/log/cron.log
# 重启 rsyslog 服务
$ sudo /etc/init.d/rsyslog restart
Restarting rsyslog (via systemctl): rsyslog.service.
# 查看日志信息
$ cat /var/log/cron.log
# (CRON) info (No MTA installed, discarding output) ❌ 没有配置邮件服务器
安装&配置邮件服务器
email / mail
# ✅ step 1
$ sudo apt-get install postfix
# 选 Local Only
$ sudo apt-get install postfix
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
下列软件包是自动安装的并且现在不需要了:
libfuse2
使用'sudo apt autoremove'来卸载它(它们)。
建议安装:
procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre postfix-lmdb postfix-sqlite sasl2-bin
| dovecot-common postfix-cdb mail-reader ufw postfix-doc
下列【新】软件包将被安装:
postfix
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 41 个软件包未被升级。
需要下载 1,503 kB 的归档。
解压缩后会消耗 4,146 kB 的额外空间。
获取:1 http://deb.debian.org/debian bullseye/main arm64 postfix arm64 3.5.17-0+deb11u1 [1,503 kB]
已下载 1,503 kB,耗时 51秒 (29.3 kB/s)
正在预设定软件包 ...
正在选中未选择的软件包 postfix。
(正在读取数据库 ... 系统当前共安装有 99543 个文件和目录。)
准备解压 .../postfix_3.5.17-0+deb11u1_arm64.deb ...
正在解压 postfix (3.5.17-0+deb11u1) ...
正在设置 postfix (3.5.17-0+deb11u1) ...
正在添加组"postfix" (GID 124)...
完成。
正在添加系统用户"postfix" (UID 116)...
正在将新用户"postfix" (UID 116)添加到组"postfix"...
无法创建主目录"/var/spool/postfix"。
Creating /etc/postfix/dynamicmaps.cf
正在添加组"postdrop" (GID 125)...
完成。
setting myhostname: raspberrypi.lan
setting alias maps
setting alias database
mailname is not a fully qualified domain name. Not changing /etc/mailname.
setting destinations: $myhostname, raspberrypi, localhost.localdomain, localhost
setting relayhost:
setting mynetworks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: loopback-only
setting default_transport: error
setting relay_transport: error
setting inet_protocols: all
/etc/aliases does not exist, creating it.
WARNING: /etc/aliases exists, but does not have a root alias.
Postfix (main.cf) is now set up with a default configuration. If you need to
make changes, edit /etc/postfix/main.cf (and others) as needed. To view
Postfix configuration values, see postconf(1).
After modifying main.cf, be sure to run 'systemctl reload postfix'.
Running newaliases
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /lib/systemd/system/postfix.service.
正在处理用于 man-db (2.9.4-2) 的触发器 ...
正在处理用于 rsyslog (8.2102.0-2+deb11u1) 的触发器 ...
Postfix Configuration ├───────────────────────────┐
│ Please select the mail server configuration type that best meets your needs. │
│ │
│ No configuration: │
│ Should be chosen to leave the current configuration unchanged. │
│ Internet site: │
│ Mail is sent and received directly using SMTP. │
│ Internet with smarthost: │
│ Mail is received directly using SMTP or by running a utility such │
│ as fetchmail. Outgoing mail is sent using a smarthost. │
│ Satellite system: │
│ All mail is sent to another machine, called a 'smarthost', for delivery. │
│ Local only: │
│ The only delivered mail is the mail for local users. There is no network. │
│ │
│ General type of mail configuration: │
│ │
│ No configuration │
│ Internet Site │
│ Internet with smarthost │
│ Satellite system │
│ Local only │
│ │
│ │
│ <确定> <取消>
Postfix Configuration ├────────────────────────────────────────────┐
│ The "mail name" is the domain name used to "qualify" _ALL_ mail addresses without a domain name. This includes │
│ mail to and from <root>: please do not make your machine send out mail from root@example.org unless │
│ root@example.org has told you to. │
│ │
│ This name will also be used by other programs. It should be the single, fully qualified domain name (FQDN). │
│ │
│ Thus, if a mail address on the local host is foo@example.org, the correct value for this option would be │
│ example.org. │
│ │
│ System mail name: │
│ │
│ raspberrypi____________________________________________________________________________________________________ │
│ │
│ <确定> <取消>
# ✅ step 2
$ sudo dpkg-reconfigure postfix
# 选 Local Only
sudo dpkg-reconfigure postfix
setting synchronous mail queue updates: true
mailname is not a fully qualified domain name. Not changing /etc/mailname.
setting destinations: raspberrypi.lan, raspberrypi, localhost.localdomain, localhost
setting relayhost:
setting mynetworks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: loopback-only
setting inet_protocols: all
WARNING: /etc/aliases exists, but does not have a root alias.
Postfix (main.cf) is now set up with the changes above. If you need to make
changes, edit /etc/postfix/main.cf (and others) as needed. To view Postfix
configuration values, see postconf(1).
After modifying main.cf, be sure to run 'systemctl reload postfix'.
Running newaliases
Postfix Configuration ├────────────────────────────────────────────┐
│ Mail for the 'postmaster', 'root', and other system accounts needs to be redirected to the user account of the │
│ actual system administrator. │
│ │
│ If this value is left empty, such mail will be saved in /var/mail/nobody, which is not recommended. │
│ │
│ Mail is not delivered to external delivery agents as root. │
│ │
│ If you already have a /etc/aliases file and it does not have an entry for root, then you should add this │
│ entry. Leave this blank to not add one. │
│ │
│ Root and postmaster mail recipient: │
│ │
│ _______________________________________________________________________________________________________________ │
│ │
│ <确定> <取消> │
│
Postfix Configuration ├────────────────────────────────────────┐
│ Please give a comma-separated list of domains for which this machine should consider itself the final │
│ destination. If this is a mail domain gateway, you probably want to include the top-level domain. │
│ │
│ Other destinations to accept mail for (blank for none): │
│ │
│ raspberrypi.lan, raspberrypi, localhost.localdomain, localhost_________________________________________ │
│ │
│ <确定> <取消> │
│
Postfix Configuration ├────────────────────────────────────────────┐
│ │
│ If synchronous updates are forced, then mail is processed more slowly. If not forced, then there is a remote │
│ chance of losing some mail if the system crashes at an inopportune time, and you are not using a journaled │
│ filesystem (such as ext3). │
│ │
│ Force synchronous updates on mail queue? │
│ │
│ <是> <否> │
│
# 重启计划任务
$ sudo /etc/init.d/cron restart
# 查看邮件
$ cat /var/mail/root
# cat: /var/mail/root: 没有那个文件或目录
$ cat /var/mail/pi
# cat: /var/mail/pi: 没有那个文件或目录
开启 cron log
$ cat /etc/rsyslog.conf
# /etc/rsyslog.conf configuration file for rsyslog
#
# For more information install rsyslog-doc and see
# /usr/share/doc/rsyslog-doc/html/configuration/index.html
#################
#### MODULES ####
#################
module(load="imuxsock") # provides support for local system logging
module(load="imklog") # provides kernel logging support
#module(load="immark") # provides --MARK-- message capability
# provides UDP syslog reception
#module(load="imudp")
#input(type="imudp" port="514")
# provides TCP syslog reception
#module(load="imtcp")
#input(type="imtcp" port="514")
###########################
#### GLOBAL DIRECTIVES ####
###########################
#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog
#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf
###############
#### RULES ####
###############
#
# First some standard log files. Log by facility.
#
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none -/var/log/syslog
#cron.* /var/log/cron.log
# 开启 cron log ✅
cron.* /var/log/cron.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
lpr.* -/var/log/lpr.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
#
# Logging for the mail system. Split it up so that
# it is easy to write scripts to parse these files.
#
mail.info -/var/log/mail.info
mail.warn -/var/log/mail.warn
mail.err /var/log/mail.err
#
# Some "catch-all" log files.
#
*.=debug;\
auth,authpriv.none;\
mail.none -/var/log/debug
*.=info;*.=notice;*.=warn;\
auth,authpriv.none;\
cron,daemon.none;\
mail.none -/var/log/messages
#
# Emergencies are sent to everybody logged in.
#
*.emerg :omusrmsg:*
refs
https://www.cnblogs.com/xgqfrms/p/15384401.html#5166823
©xgqfrms 2012-2025
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17306951.html
未经授权禁止转载,违者必究!
合集:
Raspberry Pi
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
2022-04-11 Fetch API render ArrayBuffer to object URL in js All in One
2022-04-11 js object URL & data URL All In One
2022-04-11 Fetch API & arrayBuffer & Blob All In One
2022-04-11 js charAt & charCodeAt All In One
2022-04-11 js Blob & File API All In One
2021-04-11 Beacon API in Action All In One
2021-04-11 Beacon API & Fetch API & CORS error & Preflight 403