简体   繁体   English

Cron作业无法在Ubuntu上运行

[英]Cron job won't run on Ubuntu

I have a simple shell script that runs fine when opened in terminal, but will not run at all as a cron job! 我有一个简单的shell脚本,当在终端中打开该脚本时运行良好,但根本不会作为cron作业运行!

The script is as follows: 脚本如下:

#!/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

Any reasons why this shouldn't work? 有什么原因不起作用? I'm new to Ubuntu and Cron so it might be something simple. 我是Ubuntu和Cron的新手,所以这可能很简单。

Thanks! 谢谢! (I added the job via the cron GUI, "Scheduled Tasks") (我通过cron GUI“计划任务”添加了工作)

You can use rsync directly with ssh, without fuse/mount. 您可以将rsync直接与ssh一起使用,而无需熔断器/安装。

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

But anyway, I suppose that the problem in your case is with the ssh keys. 但是无论如何,我想您的问题是ssh键。 You must check which keys are used when ssh start from cron . 当ssh从cron开始时,您必须检查使用了哪些键。 And configure ssh so, that it will use correct keys. 并配置ssh,以便它将使用正确的密钥。

Try setting this 尝试设定这个

    #!/bin/sh
    . /home/<user>/.profile

crontab is independent you might need certain profile details. crontab是独立的,您可能需要某些配置文件详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM