systemd로 30 분마다 스크립트 실행 자주 사용하지 않을 것이므로

시스템으로 부팅 한 후 30 분마다 스크립트를 실행하고 싶습니다. 나는 당신이 cron을 사용할 수 있다는 것을 알고 있지만,이 기능을 자주 사용하지 않을 것이므로 systemd로 시도하고 싶습니다.

지금까지 나는 무언가를 한 번만 실행할 수있는 단조로운 타이머 만 발견했습니다 (적어도 그렇게 생각합니다). 어떻게 것 foo.timerfoo@user.service같은 모양이 경우 뭔가 부팅 / 시스템 시작부터 30 분마다 실행하고 싶어?

foo@user.service

[Unit]
Description=run foo
Wants=foo.timer

[Service]
User=%I
Type=simple
ExecStart=/bin/bash /home/user/script.sh

foo.timer

[Unit]
Description=run foo

[Timer]
where I am stuck... ???



답변

서비스 용 파일과 이름이 같은 타이머 용 파일 두 개를 만들어야합니다.

예:

/etc/systemd/system/test.service

[Unit]
Description=test job

[Service]
Type=oneshot
ExecStart=/bin/bash /tmp/1.sh

/etc/systemd/system/test.timer

[Unit]
Description=test

[Timer]
OnUnitActiveSec=10s
OnBootSec=10s

[Install]
WantedBy=timers.target

그런 다음 명령을 사용하여 systemd를 다시로드하고로 systemctl daemon-reload타이머를 시작 systemctl start test.timer하거나 기본적으로 활성화하십시오.

시험 내용 1.sh

#!/bin/bash
echo `date` >> /tmp/2

사용 가능한 모든 타이머를 확인하는 명령 :
systemctl list-timers --all

프로젝트 페이지ArchLinux 페이지의 예제에 대한 자세한 정보


답변

타이머를 사용하지 않는 다른 옵션이 있습니다. 타이밍이 굉장히 중요하지 않고 스크립트가 오래 실행되지 않으면 간단한 작업에 적합합니다.

[Unit]
Description=Run foo

[Service]
User=%I
Restart=always
RestartSec=1800s
ExecStart=/bin/bash /home/user/script.sh


답변