简体   繁体   中英

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

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 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)

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

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

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