当手动执行时,我的备份脚本工作正常;但是没有从crontab运行。我在运行Fedora 35工作站。
crontab编辑器工作如下:
$ crontab -ecron守护进程没有运行。这些命令中的每一个都没有输出:
$ pgrep cron
$ pgrep crond
$ pidof cron
$ pidof crond我试图启动cron:
$ whereis cron
cron: /usr/share/man/man8/cron.8.gz
$ whereis crond
crond: /usr/sbin/crond /usr/share/man/man8/crond.8.gz
$ sudo service cron start
Redirecting to /bin/systemctl start cron.service
Failed to start cron.service: Unit cron.service not found.
$ sudo systemctl start cron
Failed to start cron.service: Unit cron.service not found.我尝试用cronie代替cron:
$ sudo dnf install cronie
Package cronie-1.5.7-3.fc35.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
$ sudo systemctl enable cronie.service
Failed to enable unit: Unit file cronie.service does not exist.
$ sudo systemctl start cronie.service
Failed to start cronie.service: Unit cronie.service not found.还请注意,anacron ("cronie.service")如果以前安装在Fedora系统升级期间仍然存在,但在执行新安装时,至少没有安装在Fedora 35上,这是非常令人惊讶的。
发布于 2021-12-30 03:12:25
在使用ajgringo619发布的crond位置之后,Cron执行了我的备份脚本:
$ ls -l /usr/sbin/crond
-rwxr-xr-x. 1 root root 74448 Jul 21 15:05 /usr/sbin/crond
$ sudo /usr/sbin/crond start
$ pgrep cron
121692发布于 2022-01-02 17:35:44
您的脚本可能使用/调用具有相对路径和或shell环境上下文的资源。
Cron在没有shell和环境上下文的情况下运行其脚本。
尝试使用用户nobody运行脚本:
sudo -u nobody 一旦您的脚本与用户nobody一起运行,它就可以在cron中运行。
bash shell环境上下文注入脚本的常见技巧: sed -i "2i source $HOME/.bash_script" 发布于 2022-05-25 18:12:34
如果使用此命令:
# systemctl start crond.service然后,系统将保持它为您,即使通过重新启动。因此,你不一定要记住去做!
此外,要获得状态,请使用:
# systemctl status crond.service最后,#当然意味着从根帐户,所以使用sudo (或不适当)。
https://unix.stackexchange.com/questions/684381
复制相似问题