crontab์ ์ด์ฉํ ์ค์ผ์ค ๊ด๋ฆฌ
1. ์์ ์คํฌ๋ฆฝํธ ์์ฑ
ํ
์คํธ๋ฅผ ์ํด ์์ ๋ก ๋ค์๊ณผ ๊ฐ์ hello.sh ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ์๋ค
(์ฌ๊ธฐ์ hello.sh๋ shell script program์ด ๋๋ค)
today = $(date)
echo $today " : Hello My Ubuntu World!!!"
sh hello.sh ๋ก ์คํ์ํฌ ์ ์๋ค
2. crontab ์คํ
$crontab -e
์คํํ๋ฉด ์ด๋ ๊ฒ no crontab ์ด๋ผ๊ณ ๋ฌ๋ค. ์ธ ๊ฐ ์ค ํ๋๋ฅผ ์ ํํ๋ผ๊ณ ํ๋๋ฐ, nano ํธ์ง๊ธฐ์ธ 1์ ์ ํ
3. nano ํธ์ง๊ธฐ ํ๊ฒฝ์์ ์ฃผ๊ธฐ ์ค์
*์ 5๊ฐ ์ฐ๋๋ฐ (*****) ์ฌ๊ธฐ์ *์ ๊ฐ๊ฐ ๋ํ๋ด๋ ๊ฒ์ด ๋ค๋ฅด๋ค.
์ฒซ ๋ฒ์งธ *์ ๋ถ(0~59)
๋ ๋ฒ์งธ *์ ์๊ฐ(0~23)
์ธ ๋ฒ์งธ *์ ์ผ(1~31)
๋ค ๋ฒ์งธ *์ ์(1~12)
๋ค์ฏ ๋ฒ์งธ *์ ์์ผ(0~7, 1์ด ์์์ผ 6์ด ํ ์์ผ)
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ผ๋ก ๊ทธ๋ฅ *****๋ก ์ถ๋ ฅํ๋ฉด, ๋งค ๋ถ ์คํํ๋ค๋ ๋ป์ด๋ค.
* * * * * /home/์์ด๋/hello.sh >> hello.log
// => ๋งค์ ๋งค์ผ ๋งค์์ผ ๋งค์๊ฐ 1๋ถ๋ง๋ค hello.sh ์คํํ์ฌ hello.log์ ์คํ ๊ฒฐ๊ณผ ์ ์ฅ
4. cron ์ฌ์์
$sudo systemctl restart cron
โป $crontab -l : ๋ณธ์ธ ์์ด๋์์ ์คํํ cron ๋ชฉ๋ก ํ์ธ
โป $crontab -r : ๋ณธ์ธ ์์ด๋์์ ์คํํ cron ์ ์ฒด ์ญ์
โป $cat /var/log/syslog | grep CRON --> crontab ๋ก๊ทธ ํ์ธ
5. hello.log ํ์ผ์์ 1๋ถ๋ง๋ค ์ถ๋ ฅ๋๋์ง ํ์ธ
์ ๋ ์ค์๋ก hello.sh๋ง ๋ฐํํ๋ฉด ๋ฐ์ ๋ง๋ค์ด์ ํ์ผ ์์น ์ฎ๊ฒจ์ฃผ๊ณ ์คํ์์ผฐ์ต๋๋ค
๋ค์ํ ์ค์ผ์ค ๋ฑ๋ก ๋ฐฉ๋ฒ
์) * * * * * hello.sh --> 1๋ถ๋ง๋ค hello.sh๋ฅผ ์คํ
์) 0 4 * * * hello.sh --> ๋งค์ผ 04์์ hello.sh๋ฅผ ์คํ
์) 0 4 * * 1-5 hello.sh --> ์์์ผ๋ถํฐ ๊ธ์์ผ 04์์ hello.sh๋ฅผ ์คํ
์) */10 4 * * * hello.sh --> ๋งค์ผ 04์ 10๋ถ, 04์ 20๋ถ, 04์ 30๋ถ,04์ 40๋ถ, 04์50๋ถ์ hello.sh๋ฅผ ์คํ
์) 0 */6 * * * hello.sh --> 6์๊ฐ๋ง๋คhello.sh๋ฅผ ์คํ
์) 0 8 * * 0,6 hello.sh --> ํ ์์ผ, ์ผ์์ผ 08์์ hello.sh๋ฅผ ์คํ
- crontav -l ๋ช
๋ น์ ํตํด ์ ์ฅ๋ cron ๊ธฐ๋ก์ ๊ณ์ ๋ก๊ทธ์์ ์์ ์ญ์ ๋จ
- ๋ฐ๋ผ์, ์๊ตฌ ์ง์ํ ๋ช
๋ น ๋ฐ ์ ์ฒด ์์คํ
๋ ๋ฒจ์์ ์ํํ ์ค์ผ์ค ๊ด๋ฆฌ๋
/etc/crontab์ ์ ์ฅํ์ฌ์ผ ํจ
'๐ฅ๏ธ > Linux & macOS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[macOS] mac m1์ oracle ์ค์นํ๊ธฐ ์ค๋ฅ๋ค๊ณผ ๊ฒฐ๋ก (3) | 2023.06.06 |
---|---|
[macOS] mac m1 homebrew ์ค์น ์ค๋ฅ ํด๊ฒฐ ! (0) | 2023.05.31 |
[Linux] ๋ฆฌ๋ ์ค ๊ฐ๋จํ ์ญ์ฌ (0) | 2023.04.19 |
[Linux] ์ฐ๋ถํฌ Tomcat ์ค์น + ๊ฐ์ํธ์คํ ์ค์ (0) | 2023.03.31 |
[Linux] ์ฐ๋ถํฌ Apache ์ค์น (0) | 2023.03.31 |