서비스에서 crontab을 편집할 수 없습니다

서비스에서 crontab을 편집할 수 없습니다

sudo service autoshutdown start매일 예약하거나 중단하여 자동으로 닫고 싶습니다 sudo service autoshutdown stop.

/etc/systemd/system/autoshutdown.service

[Unit]
Description=AutoShutdown
[Service]
User = root
Type = oneshot
ExecStart=/etc/systemd/system/autoshutdown.sh
ExecStop=/usr/bin/crontab -r
[Install]
WantedBy=multi-user.target

/etc/systemd/system/autoshutdown.sh

#!/bin/bash
echo "scheduling a shutdown 19:00..."
whoami
crontab -l | cat - /etc/systemd/system/autoshutdown.txt > crontab.txt && crontab crontab.txt
echo "crontab is now"
crontab -l

/etc/systemd/system/autoshutdown.txt

50 18 * * * /sbin/shutdown +10

모든 것이 훌륭했습니다. 그래서 starting 서비스가 올바르게 실행됩니다. statusing 서비스를 볼 때

[생략] autoshutdown.sh[11178] : 19시 종료 예약...

[생략] autoshutdown.sh[11178]: 루트

[생략] autoshutdown.sh[11178]: 50 18 * * * /sbin/shutdown +10

그래서 모든 것이 괜찮아 보입니다. 그러나 후자는 sudo crontab -l빈 테이블을 반환합니다.

내 크론탭은 "어디"로 갔나요?

아마도[비]관련 질문:

  1. 루트가 아닌 사용자로 crontab을 편집할 수 없습니다
  2. 크론탭을 편집할 수 없습니다

답변1

좋습니다. 원하는 동작에 가장 적합한 옵션은 RemainAfterExit=yes(기본값: 아니요)입니다.

그렇지 않으면 ExecStart완료 되면 ExecStop즉시 실행하십시오.

원천:FreeDesktop 시스템 매뉴얼

관련 정보