我有一个简单的 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/