I am trying to achieve run a shell script periodically in a docker container with crontab. Dockerfile:
FROM ubuntu:latest
RUN apt-get update && apt-get -y install cron nano
RUN mkdir -p /custom/bin
COPY ./myscript.sh /custom/bin/myscript.sh
RUN chmod +x /custom/bin/myscript.sh
COPY ./dockerconfigs/crontab /etc/cron.d/crontab
RUN chmod 0644 /etc/cron.d/crontab
RUN crontab /etc/cron.d/crontab
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log
myscript.sh:
#!/bin/bash
echo "test" > /test.txt
touch /test2.txt
crontab:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * /custom/bin/myscript.sh
* * * * * touch /abc.txt
I can see that 2. crontab is running successfully. I can see /abc.txt file on every minute. But it seems like myscript.sh is not working. I can not see any /test.txt or /test2.txt file. Also there is nothing in the /var/log/cron.log file. I've tried with different base image (php:7.2-cli) but no luck.
Also I can confirm that my script is working when I try to run it on command line.
PS: I can see 'abc.txt'$'\r' instead of abc.txt file in folders. I am using windows 10 and docker desktop.