cron笔记,包含cron不执行shell脚本的解决办法
也许shell脚本本身可以执行,但是cron中不能执行,需要像下面这样设置
cron-for-run-per-1h.cron1 2 3
| SHELL=/bin/bash 0 * * * * . /etc/profile;/bin/sh /pathto/run.sh
|
run.sh1 2 3 4 5
| #!/bin/bash PATH=/opt/someApp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin LOGS_FILE="/pathto/logs/$(date "+%Y-%m-%d-%H-%M-%S").log" cd /pathto docker-compose up >> $LOGS_FILE 2>&1
|
最后设置到cron
run.sh1
| crontab /pathto/cron-for-run-per-1h.cron
|
warning
使用此命令会覆盖之前所有的cron任务
如果你不想覆盖之前的,那么就/etc/cron.d
中新建文件,然后写进去。
warning
cron的话基本必有一个?
,它仅可存在于dayofmouth
或者dayofweek
个人docker配置备份
Dockerfile1 2 3 4 5 6
| FROM python:3.11 WORKDIR /bin/test COPY ./requirements.txt ./ RUN pip install -r ./requirements.txt ENTRYPOINT [ "python" ] CMD [ "./test.py" ]
|
docker-compose.yml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| version: '3.8' services: enhanced-faas: build: context: ./ container_name: enhanced-faas volumes: - "./:/bin/test" expose: - 443,80 command: ./main.py networks: - nginx-proxy
networks: nginx-proxy: external: true
|