Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?
cronã§pythonã¹ã¯ãªãããèªåå®è¡ããå ´åã®è½ã¨ãç©´æè¿pythonã使ã£ã¦åç»ãèªåçæãã¦å®ææ稿ãããbotãä½ã£ã¦ã¿ã¾ããã botãä½ãã®ã£ã¦ãã£ã¨ç°¡åãªã¤ã¡ã¼ã¸ã ã£ãã®ã§ãããå°ããªããããã¤ã³ããããã¤ããã£ã¦æå¤ã¨æãããã¾ãããã¨ãããã¨ã§ä»åã¯ãã®æ å ±ãã·ã§ã¢ãã¦ããã¾ãã ãã¼ã«ã«ã®ãã¹æå®ã¯çµ¶å¯¾ãã¹ã§æå®ããPythonã¹ã¯ãªããå ã®ãã¼ã«ã«ãã¹ãæå®ããã¨ãã¯çµ¶å¯¾ãã¹ã§è¨è¿°ããã¨å®å¿ã§ããç¸å¯¾ãã¹ã§è¨è¿°ããã¨æã£ãåä½ããã¦ãããªãå¯è½æ§ãããã¾ãã #coding:utf-8 f = open('test.txt','w') ä¾ãã°ä¸ã®ãããªhoge.pyã¨ããã¹ã¯ãªãããcrontabã§python ~/any/path/hoge.pyã®ããã«ãã¦å®è¡ããã¨ãã¾ããããã¨test.txtã¯crontabãå®è¡ãã¦ããã¦ã¼ã¶ã®ããã©ã«ããã£ã¬ã¯ããªã«çæ
cronã5åããã10åããã15åãããã«å®è¡ãã cronã§5åããã10åããã15åãããçã®âåãããcronãå®è¡ããæ¹æ³ã§ã $ crontab -e # 5åããã«å®è¡ */5 * * * * command # 10åããã«å®è¡ */10 * * * * command # 15åããã«å®è¡ */15 * * * * command cronã3åã8åã13åçã®ã5åããã«å®è¡ãã 5åããã®å ´åãã*/5 * * * *ãã ã©ã0åã5åã10åã«ãªããã3åã8åã13åãªã©ä¸éå端ãªæéã«å®è¡ãããå ´åã¯ä»¥ä¸ã¨ãªãã¾ã $ crontab -e # 3å,8å,13å,18å,23åã»ã»ã»ã®5åããã«å®è¡ 03-59/5 * * * * command cronã2æéããã3æéãããã«å®è¡ãã cronã§2æéããã3æéãããçã®âæéãããcronãå®
cron (ã¯ã¼ãã³) ã¨è¨ãã°å®æå®è¡ãã¦ãããããªãã¿ã®ã·ã³ãã«ãªæ©è½ã ãããã«ã¯å¥¥è¡ããããæ§ã ãªãã¦ãã¦ãããã ããã§è¨å®ããã¨ãã®ã¬ã¤ãã©ã¤ã³ãã¾ã¨ããã æ·±ãã¯ãã¾ã説æåºæ¥ãªãã®ã§æ°ã«ãªãç¨èªæ©è½ãè¦ã¤ãããå¥éæ¤ç´¢ãã¦ããã ãããã cronã®å ´æ /etc/crontab crontabã®æ¸å¼ æèãã¦ããã«æ¸ãå¿ è¦ã¯ç¾å¨ãã¾ãç¡ãã RedHatç³»ã¯éæ¨å¥¨ã¨ãè¨ããã¦ããæ ¹æ ã¯ããããããªãã rootã§å®è¡ãããã #crontabã®æ¸å¼ # ï¼è¡é ã® # ãã¼ã¯ã¯ã³ã¡ã³ãè¡ã示ãï¼ # +------------ å (0 - 59) # | +---------- æ (0 - 23) # | | +-------- æ¥ (1 - 31) # | | | +------ æ (1 - 12) # | | | | +---- ææ¥ (0 - 6) (æ¥ææ¥=0)
cron ã§æå®æéã«å®è¡ããããã«è¨å®ããã®ã«ããªããæå¾ ããåä½ããã¦ããªãã ãããªãã¨ãããã¾ãããã ãããªæã¯ãå大ãªã syslog æ§ã«å©ãã¦ãããã¾ãããã 1. rsyslog ã§cronç¨ã®ãã°ãåãããã«è¨å®ãã ã»rsyslog ã®è¨å®ãã¡ã¤ã«ï¼/etc/rsyslog.confï¼ãéãã sudo nano /etc/rsyslog.conf ã»cronç¨ã®ãã°ã®è¨å®è¡ãã³ã¡ã³ãã¢ã¦ãããã¦ããã®ã§ # ãæ¶ãã cron.* /var/log/cron.log ï¼ä¸é¨æç²ãã¦ããã ããªã®ã§ãééã£ã¦ãä¸è¨ã®ã¿æ®ãã¨ãã¯ããã¦ãã ããã ã»è¨å®ã®å¤æ´å¾ã¯åèµ·å sudo /etc/init.d/rsyslog restart 2. cron ã®ãã°ã¬ãã«ãè¨å®ãã ã»cron ã®è¨å®ãã¡ã¤ã«ï¼/etc/default/cronï¼ãéãã sudo nano /e
çµè«ããè¨ãã¨ã以ä¸ã®ããã«run-partsã³ãã³ãã--testãªãã·ã§ã³ã§å®è¡ãããã¨ã§ãcron.dailyã§å®è¡ãããã¹ã¯ãªããåã確èªãããã¨ãã§ãã¾ããåæ§ã«cron.hourly, cron.weekly, cron.monthlyã確èªå¯è½ã§ãã run-parts --test /etc/cron.daily cronã¹ã¯ãªãããä½æããã¨ãã«ãã¤ãè¦å¿ãã¦ããã®ãããã®cronã¹ã¯ãªãããã¡ããã¨åããã©ãã確èªãããã¨ã§ãããã®ãªãã·ã§ã³ããã£ã¨æ©ãç¥ã£ã¦ããã°ãããä»ã¾ã§ã¯ãã·ã³ã®æå»ãããããããããã¨syslogåºåãã¦ã¹ã¯ãªããã®å®è¡ã確èªããããè²ã ã¨é¢åãªãã¨ããã¦ãã¾ããã ãããrun-partsã®manãã¼ã¸ãè¦ãã¨åããã®ã§ãããubuntuãªã©Debianç³»ã®ãã£ã¹ããªãã¥ã¼ã·ã§ã³ã§ã¯ãcronã¹ã¯ãªããã®ãã¡ã¤ã«åã«è¨±ããã¦ããæååã¯ã(^
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}