
command/script
기본 작업 command/script
(Task-A)이 정의된 시간 창/기간을 초과하는 동안 병렬 모드에서 다른(Task-B)를 실행하는 방법 ?crontab
@ 프로덕션 환경, gnome-terminal
.
답변1
이는 기본적으로 발생합니다. 크론 실행모두거의 동시에 특정 분 동안 예약된 작업입니다. 대기열이 없으며 시간 창/기간도 없습니다. 시작 시간 세트만 있습니다.
답변2
l0b0이 언급했듯이그의 대답에, crontab 파일은 작업 시작 시간만 지정합니다. 작업을 실행하는 데 몇 시간이 걸리더라도 상관하지 않으며, 이전 작업 구현이 여전히 실행 중이더라도 다음 시작 시간이 되면 다시 시작할 것입니다.
설명에 따르면 작업 A를 실행하는 데 시간이 너무 오래 걸리면 작업 B를 시작하려는 것 같습니다.
두 작업을 하나의 동일한 스크립트로 결합하여 이를 달성할 수 있습니다.
#!/bin/sh
timeout=600 # time before task B is started
lockfile=$(mktemp)
trap 'rm -f "$lockfile"' EXIT INT TERM QUIT
# Start task A
# A "lock file" is created to signal that the task is still running.
# It is deleted once the task has finished.
( touch "$lockfile" && start_task_A; rm -f "$lockfile" ) &
task_A_pid="$!"
sleep 1 # allow task A to start
# If task A started, sleep and then check whether the "lock file" exists.
if [ -f "$lockfile" ]; then
sleep "$timeout"
if [ -f "$lockfile" ]; then
# This is task B.
# In this case, task B's task is to kill task A (because it's
# been running for too long).
kill "$task_A_pid"
fi
fi