简体   繁体   中英

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!

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.

Thanks! (I added the job via the cron GUI, "Scheduled Tasks")

You can use rsync directly with ssh, without fuse/mount.

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. You must check which keys are used when ssh start from cron . And configure ssh so, that it will use correct keys.

Try setting this

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

crontab is independent you might need certain profile details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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