Passer au contenu

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.

demandé il y a 3 mois95 vues

2 réponses
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

EXPERT

répondu il y a 3 mois

AWS
EXPERT

vérifié il y a 3 mois

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

répondu il y a 3 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.