跳至內容

EC2 ubuntu crob job failure

0

Hi,

I’m trying to set up a cron job on an Ubuntu EC2 instance, but it keeps failing with a Permission denied error.

These are the steps I followed:

  1. Edited the crontab:

    crontab -e
    
  2. Added the following entry to run every minute for testing:

    * * * * * /usr/bin/docker system prune -af
    
  3. Verified the entry was saved:

    crontab -l
    

The cron service is running, but when I check the logs I see:

Mar 10 18:06:01 remote-docker-engine-amd-01 cron[19243]: Permission denied
Mar 10 18:06:01 remote-docker-engine-amd-01 CRON[19243]: Permission denied

The command itself works when I run it manually as the same user:

/usr/bin/docker system prune -af

So Docker permissions seem fine when executed interactively, but the job fails when triggered by cron.

I also tried reinstalling the cron package, but the issue persists.

Am I missing something in the cron configuration or environment? Any guidance would be appreciated.

Thanks.

已提問 3 個月前檢視次數 95 次
2 個答案
1

Hello.

Even if I set "sudo" in the command set in cron, it fails to execute?
If you run it as the root user, it should generally run successfully.
To troubleshoot, start by enabling sudo.
https://stackoverflow.com/questions/70099692/crontab-sudo-docker-permission-denied

專家
已回答 3 個月前
AWS
專家
已審閱 3 個月前
0

When you run docker commands interactively, your shell session has access to the Docker socket (usually docker.sock) because your user is in the docker group. However, cron jobs run in a minimal environment without loading group memberships the same way.

For a quick fix, try to run the cron job as root:

sudo crontab -e

AWS
已回答 3 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。