Home > Net >  Cron won't execute none of my commands on Ubuntu 21.10 impish
Cron won't execute none of my commands on Ubuntu 21.10 impish

Time:10-27

I'm trying to run a Docker container every other minute that is stopped via cron job but it seems not working.

What I've done is launch the command crontab -e and add the line

*/1 * * * * docker start sender >> /home/cronlog.log 2>&1

I've added the user group to Docker as explained here (in fact I can access docker from the terminal without sudo)

I have also tried to add the command into a script as below

*/1 * * * * /home/start_container.sh >> /home/cronlog.log 2>&1

with the script containing

#!/bin/sh
docker start sender

but still, nothing happens. The cron process is working tho as using the command ps -ef | grep cron I got

root         881       1  0 08:42 ?        00:00:00 /usr/sbin/cron -f -P
nicola     10905   10178  0 11:31 pts/0    00:00:00 grep --color=auto cron

Am I missing something? (Obviously, the commands work if launched manually from the terminal)

CodePudding user response:

Try using the docker path instead.

type the following command to get the path of docker.

$ where docker

/usr/bin/docker
/bin/docker

then try any one of the paths in the cron script

*/1 * * * * /bin/docker start sender >> /home/cronlog.log 2>&1

or

*/1 * * * * /usr/bin/docker start sender >> /home/cronlog.log 2>&1

CodePudding user response:

It turned out that, for some reason, the cron doesn't like the /home/ (at least, in this specific instance)

I've fixed using another path such as

*/1 * * * * docker start sender >> /tmp/cronlog.log 2>&1
  • Related