Task automation with cron based on Alpine distro
463
Crontasks DockersDocker for task automation using Python and Bash shell scripts
The humbertovarona/debcrontasks:v1, humbertovarona/ubucrontasks:v1, and humbertovarona/alpcrontasks:v1 docker images are designed to execute scheduled tasks using cron. This image includes Python 3, various downloading utilities, and provides the capability to mount local scripts and cron tasks. Logs are accessible within the container, facilitating easy monitoring and debugging of cron jobs.
1.0
2024-06-28
https://doi.org/10.5281/zenodo.13340172
Humberto L. Varona, Silena Herold-Garcia. (2024). Dockers for task automation using Python and Bash shell scripts. (1.0). Zenodo. https://doi.org/10.5281/zenodo.13340172
To pull the Debian-based version of the debcrontasks Docker image, run the following command:
docker pull humbertovarona/debcrontasks:v1
To pull the Ubuntu-based version of the ubucrontasks Docker image, run the following command:
docker pull humbertovarona/ubucrontasks:v1
To pull the Ubuntu-based version of the alpcrontasks Docker image, run the following command:
docker pull humbertovarona/alpcrontasks:v1
debian:bullseye-slim, ubuntu:22.04, and alpine:20240606/var/log/cron.logEnsure your project directory is structured as follows:
work_directory /
├── crontasks/
│ └── crontab
├── scripts/
│ ├── test_task.py
│ ├── get_datetime.sh
│ ├── getfiles.sh
│ ├── download_data.sh
│ ├── process_data.py
│ └── print_datetime.py
└── shared/
└── data/
To run this image, you need to mount your local crontasks and scripts directories into the container. This ensures that your scripts and cron jobs are correctly picked up and executed by the container's cron daemon.
Execute the following command to run the container with the necessary volumes mounted:
docker run -d --name my-cron-container -v "$(pwd)/shared/data:/usr/src/app/shared/data" -v "$(pwd)/crontasks:/usr/src/app/crontasks" -v "$(pwd)/scripts:/usr/src/app/scripts" humbertovarona/debcrontasks:v1
Or
docker run -d --name my-cron-container -v "$(pwd)/shared/data:/usr/src/app/shared/data" -v "$(pwd)/crontasks:/usr/src/app/crontasks" -v "$(pwd)/scripts:/usr/src/app/scripts" humbertovarona/ubucrontasks:v1
Or
docker run -d --name my-cron-container -v "$(pwd)/shared/data:/usr/src/app/shared/data" -v "$(pwd)/crontasks:/usr/src/app/crontasks" -v "$(pwd)/scripts:/usr/src/app/scripts" humbertovarona/alpcrontasks:v1
crontab FileYour crontab file should be placed in the crontasks/ directory and might look like this:
# Run test_task.py every minute
* * * * * python3 /usr/src/app/scripts/test_task.py >> /var/log/cron.log 2>&1
# Run getfiles.sh every 5 minutes
*/5 * * * * /usr/src/app/scripts/getfiles.sh >> /var/log/cron.log 2>&1
Ensure that all scripts in the scripts/ directory are executable. You can do this by running the following command:
chmod +x scripts/*
To monitor the execution of your cron jobs, you can access the cron log inside the container. Use the following command to enter the container's shell:
docker exec -it my-cron-container /bin/bash
Once inside the container, you can view the cron log by executing:
tail -f /var/log/cron.log
To customize the scripts and cron tasks, simply edit the files in your local scripts and crontasks directories. These changes will be reflected in the container the next time it starts.
If you wish to contribute to this project, please open an issue or submit a pull request on Zenodo or GitHub. Contributions to enhance the functionality or fix issues are always welcome.
This project is licensed under the MIT License. Feel free to use and modify the code as per the terms of the license.
This Docker was developed by specialists at the Centro de Estudos e Ensaios em Risco e Modelagem Ambiental (CEERMA) as part of the project identified under Process No.: APQ-0235-1.08/23, funded by FACEPE/APAC. This Docker was designed to support the Núcleo de Oceanografia Operacional do Estado de Pernambuco (NOPE) project.
It is available for free use by any individual or institution in scientific research, such as scientific articles, technical reports, books, and other scientific documents. It is important to note that proper citation of this Docker is required in the references of any scientific research in which it is used. Additionally, acknowledgments in such scientific articles, technical reports, books, and other scientific documents must explicitly include an acknowledgment to CEERMA as an institution.
For any commercial use of this Docker, it is necessary to contact the coordinator and/or vice-coordinator of the NOPE project and CEERMA beforehand to establish the corresponding terms and conditions of use.
Content type
Image
Digest
sha256:23b3df75d…
Size
67.8 MB
Last updated
over 1 year ago
docker pull humbertovarona/alpcrontasks