我曾尝试在Linux中使用'at'命令,但我试图设置变量,但无法使其正常工作。
以下尝试:
sudo echo "KEY='VALUE' DIRECTION='D' sh run.sh" | at now + 2 minute
# Above does not run the docker-compose
sudo echo "KEY='VALUE' DIRECTION='D' sh run.sh" | at now + 2 minute
# Above runs docker-compose command immediately but not in 2 minutes
# run.sh
# SET LOGFILE LOCATION
LOG_FILE="/var/log/at/test.log"
FLIGHT_FILE="flight.yaml" docker-compose up --abort-on-container-exit >> "${LOG_FILE}"
[如果有比使用'at'命令更好的方法,我也可以接受。
提前谢谢您
有2种可能的方法-
简单的一个-
创建文件/ etc / systemd / system / dc-test.service
[Unit]
Description=My Docker Compose runner
[Service]
User=%I
Restart=always
RestartSec=600s
ExecStart=/bin/bash /home/user/run.sh
上面将每600秒运行一次脚本。