일반적으로 스케줄 서비스의 이름이다.
crond 은 cron daemon을 의미한다. 실제로 crontab에서 작업을 읽어서 실행하는 daemon이다. 그러므로 crontab이 변화가 생기면 crond를 재시작해 주어야 한다.
crontab은 실행주기 혹은 실행시간이 지정된 작업의 모음이다.
sudo systemctl list-unit-files | grep crond
> sudo systemctl list-unit-files | grep crond
crond.service enabled
sudo yum update -y
sudo yum install -y cronie
참고: -y, --assumeyes: answer yes for all questions (모든 대답에 yes를 기본으로 설정)
crontab -l
crontab -e
crontab -r
sudo systemctl start crond
sudo systemctl restart crond
sudo systemctl enable crond
* * * * * (명령어)
[분, 시, 일, 월, 년] ~/rsync.sh
* * * * * ~/rsync.sh
* */12 * * * ~/rsync.sh
0 4 * * * ~/rsync.sh
* 4 * * * ~/rsync.sh
rsync를 이용해서 1분마다 파일을 복사하는 예제
> crontab -e
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * /home/ec2-user/rsync_scripts/rsync_logs
#!/bin/bash
nowdate=$(date "+%Y-%m-%d %H:%M:%S")
echo "Today is ${nowdate}, cron daemon execution complete." >> /home/ec2-user/rsync_scripts/crond_execution.log
echo 'rsync logs ...'
rsync -avzh /srv/my-server/logs/ /efs-my-folder/logs/
1분마다 rsync_logs.sh
저장한 후 재 반영과정이 필요하다.
sudo systemctl restart crond
crond가 동작할 아래와 같은 내용을 확인 할 수 있다.
vim /var/spool/mail/ec2-user
오류 내용 및 실제 동작내역도 확인할 수 있다.
sudo chmod +x ~/rsync_scripts/rsync_logs.sh
파일에 실행권한을 추가해 주면 해결된다.