Unable to Run AWS S3 sync as a Cron Job

Hi,

Sorry in advance, I don’t know if my issue is related to Hestia Control Panel or not.
So I’m having trouble running aws s3 sync as a cron job. I did it manually via ssh client and it worked, but it failed when doing it via cron job.

Can anyone help with some direction?

image
Successfully when did it manually.


These are not working

You can’t run sudo from admin user any more …

So what should i do? Previously i didn’t use sudo, and it also failed.

login as root, do a crontab -e and add your cronjob there. So it will be executed under root permission.

2 Likes

I’ve done it before too. But it still didn’t work. Then I deleted it again.

Now I’ll try to create it again, I’ll update the result.

Still not working.


using cron

image
using ssh command

So, the /usr/local/backup.sh is working via ssh, but not working via cron.

Any suggestion?

Probally paths are not correct working use full paths…

It seems the path is correct, because /usr/local/backup.sh works when I run it via terminal, but it fails if run via cron.

You’re running it with sh, but does the script have execute permissions? Does it work if you just run it directly, without sh?

/usr/local/backup.sh
1 Like

try these:

cd /usr/local
sudo mv backup.sh backup
sudo chmod u+rwx,g+rx,o+rx backup

then your cron must be like this: sudo /usr/local/backup

and it should work!

SOLVED!

Yes, the script has execute permissions, so the problem is not related to permissions.

Based on your suggestion to run without sh, it turns out the script doesn’t work, with the notification: -bash: /usr/local/backup.sh: /bin/bash^M: bad interpreter: No such file or directory

After I googled, the problem is at the “end of file” of the file. I created the file (backup.sh) using Notepad++ on Windows, with CR LF as the line ending (\r\n). But because Unix uses different line endings so it can’t read the file created on Windows.

The solution is to rewrite the script in Unix env using nano or vi (I do not try it). Or edit the file using Notepad++, using the EOL Conversion menu, change it to Unix (LF) (this is what I did).

Thank you very much for your help!

2 Likes

I haven’t tried this method, but I’ve had success with the method I described above.

Thanks!

You are welcome.

Next time you can use dos2unix command to convert the file:

dos2unix /usr/local/backup.sh
3 Likes

OK thanks :saluting_face:

2 Likes