为什么我的 bash 脚本可以在终端中运行,但在使用 crontab 时却不行?

Why does my bash script work in a terminal, but not when using crontab?

为什么我的 bash 脚本在终端中运行,但在使用 crontab 时却不行?

我运行流行OS(Debian/Ubuntu)

我的 crontab 行:

0 * * * * /bin/bash root /home/henry/yupdate.sh > /dev/null 2>&1

这是我的脚本yupdates.sh:

#!/bin/bash

PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
sudo apt update 
sudo apt upgrade -y  
flatpak update -y

脚本 运行 在终端中正常。

crontab 在我的 /var/log/syslog

中 运行ning
Jul 30 17:00:01 pop-os CRON[17989]: (root) CMD (/bin/bash root
/home/henry/yupdate.sh > /dev/null 2>&1)

我做错了什么?

用户名先于系统crontab中运行的命令。使用

0 * * * * root /bin/bash /home/henry/yupdate.sh > /dev/null 2>&1

相反。