linux - Cron 作业无法在 Ubuntu 上运行

标签 linux bash shell ubuntu cron

我有一个简单的 shell 脚本,在终端中打开时可以正常运行,但根本不会作为 cron 作业运行!

脚本如下:

#!/bin/sh
/usr/bin/sshfs example.com: /mnt
/usr/bin/rsync -az -v --progress -h --delete /mnt/html/ /home/user/html/
/bin/fusermount -u /mnt

有什么理由说明这不起作用? 我是 Ubuntu 和 Cron 的新手,所以这可能很简单。

谢谢! (我通过 cron GUI 添加了作业,“计划任务”)

最佳答案

您可以直接将rsync与ssh一起使用,无需fuse/mount。

rsync -az -v --progress -h --delete example.com:/mnt/html/ /home/user/html/

但无论如何,我认为您的情况的问题在于 ssh key 。 您必须检查从 cron 启动 ssh 时使用了哪些 key 。并配置 ssh,使其使用正确的 key 。

关于linux - Cron 作业无法在 Ubuntu 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14543715/

相关文章:

PHP 转义 shell arg 不需要的行为

c - 如何将本地结构作为参数传递给 pthread_create?

php - 什么是选项 +FollowSymLinks?

Linux按日期排序 "ls -al"输出

bash - 如何使用双列映射文件将与第二个文件中的一列关联的数据分配给另一个文件中的另一列

linux - 在 find 中将每个参数传递给 -exec 后的状态

c - C 中出现段错误

linux - 使用脚本通过 SSH 自动执行任务

Linux命令从tar中提取单个文件作为字节/字节数组

bash - Docker Shell脚本未按预期参数化