1. cron 접근제어
1.1. cron.deny
디렉토리가 존재하고 파일이 비어있지 않다면 이 파일에 올라온 사용자를 제외하고 모든 사용자는 crontab을 사용할 수 있다.
# cron.deny 파일에 admin 등록 [root@Linux ~]# vi /etc/cron.deny --------------------------- admin --------------------------- [root@Linux ~]# su - admin [admin@Linux ~]# crontab -e You (admin) are not allowed to use this program (crontab) See crontab(1) for more information |
1.2. cron.allow
디렉토리가 존재하고 파일이 비어있지 않다면 이 파일에 올라온 사용자만 crontab을 사용할 수 있다.
# cron.allow 파일에 admin 등록 [root@Linux ~]# vi /etc/cron.allow --------------------------- admin --------------------------- [root@Linux ~]# su - harry [harry@Linux ~]# crontab -e You (harry) are not allowed to use this program (crontab) See crontab(1) for more information |
2. 타이머
주기적인 작업 예약 및 실행을 포함하여 시스템 서비스 및 데몬을 관리하는 방법을 제공하는 시스템 및 서비스 관리자다.
cron과의 차이점
cron보다 직관적이고 시간대를 초단위로 지정 할 수있으며 시스템 시작 또는 종료와 같은 특정 이벤트를 기반으로 작업을 트리거하는 데 사용할 수도 있다
예시
현재 날짜와 시간을 파일로 출력하기
[root@Linux tmp]# cd /etc/systemd/system [root@Linux system]# vi date-time.service # vi 편집기 [Unit] Description=Write the current date and time to a file [Service] Type=oneshot ExecStart=/bin/bash -c "date > /tmp/date-time.txt" ---------------------------------------------------------------- [root@Linux system]# vi date-time.timer # vi 편집기 [Unit] Description=Run the date-time service every a minutes [Timer] OnBootSec=1min OnUnitActiveSec=1min Unit=date-time.service [Install] WantedBy=timers.target ------------------------------------------------------------------ [root@Linux system]# systemctl start date-time.timer # 타이머 실행 [root@Linux system]# systemctl status date-time.timer # 상태 확인 ● date-time.timer - Run the date-time service every 5 minutes Loaded: loaded (/etc/systemd/system/date-time.timer; disabled; vendor pre> Active: active (waiting) since Thu 2023-05-04 12:49:57 KST; 3min 12s ago [root@Linux system]# cd /tmp # tmp 디렉토리 이동 [root@Linux tmp]# ls # date-time.txt 파일 확인 date-time.txt [root@Linux tmp]# cat date-time.txt # 시간이 저장되는지 확인 Thu May 4 12:51:17 PM KST 2023 |