[root@srv7 0722]# crontab -e
* * * * * echo "hello" >> test.txt
분-시-일-월-요일
*은 상관없다는 뜻
모든 분(매 분마다) 다음을 실행해라
[root@srv7 0722]# systemctl restart crond
[root@srv7 0722]# cat ~/test.txt
hello
hello
* * * * * echo $(date +\%y\%m\%d\%H\%M) >> test.txt
2 * * * * : 매 시 2분마다 실행(ex.1시2분, 2시2분, 3시2분…)
/2 * * * : 2분마다 실행 (1분 → 3분→5분..)
[root@srv7 0722]# crontab -e
# 파일 내용
* * * * * /root/backup.sh
[root@srv7 0722]# touch /root/backup.sh
[root@srv7 0722]# chmod +x /root/backup.sh
[root@srv7 0722]# vi /root/backup.sh
# 파일 내용
#!/bin/bash
echo "hello backup" >> /root/backup.txt
yum -y install git
실행 시간은 … cron에서 정하기
1 19 * * * /root/backup.sh : 매일 저녁 7시 1분마다 밑에 내용 실행
실행 파일의 내용은
clone은 현재 없는 디렉토리로 설정해야하므로 날짜, 시간, 분 등을 이용해 겹치지 않게 생성할 수 있다.
git clone https://…. /root/$(date +%y%m%d%H%M)
# 앞에 \ 하면 alias 무력화 시켜 -i 없이(물어보지 않고 copy)
\cp /root/1351/* /var/www/html
github의 해당 디렉토리에서 파일 하나 추가 하고
systemctl restart httpd
Quiz
[확인]
날짜랑 이런거를 변수에 넣고, 디렉토리를 그 변수이름으로
깃허브에 index.html 생성 후 push
/root/backup.sh 내용 수정
```bash
#!/bin/bash
backupdate=$(date +\%y\%m\%d\%H\%M)
git clone https://github.com/dustndus8/gitupdate.git /root/$backupdate
\cp /root/${cur_date}/* /var/www/html
systemctl restart httpd
crontab -e
* * * * * /root/backup.sh


만약, index.html 등 웹서버 관련 수정하고싶으면
[root@srv7 0722]# vi /etc/httpd/conf/httpd.conf
에서 수정 후 재시작
[root@srv7 0722]# systemctl restart httpd
/var/www/html 모든 파일을 tar xz로 묶고 압축
tar cfJ $testdate.tar.xz /var/www/html