尊龙凯时人生就是博

ÔõÑùʹÓÃSystemdºÍCrontabÔÚLinuxϵͳÖÐÉèÖÃ׼ʱʹÃüµÄÓÅÏȼ¶

ÔõÑùʹÓÃSystemdºÍCrontabÔÚLinuxϵͳÖÐÉèÖÃ׼ʱʹÃüµÄÓÅÏȼ¶ £¬ÐèÒªÏêϸ´úÂëʾÀý

ÔÚLinuxϵͳÖÐ £¬ÎÒÃǾ­³£ÐèÒªÉèÖÃ׼ʱʹÃüÀ´Ö´ÐÐһЩÖظ´ÐԵIJÙ×÷ £¬ÀýÈç׼ʱ±¸·ÝÎļþ¡¢°´ÆÚÕûÀíÈÕÖ¾µÈ¡£È»¶ø £¬²î±ðµÄʹÃü¿ÉÄܾßÓвî±ðµÄÓÅÏȼ¶ £¬ÓÐЩʹÃüÐèÒª¸ü¸ßµÄÓÅÏȼ¶À´È·±£Æä׼ʱִÐÐ £¬¶øÓÐЩʹÃüÔò¿ÉÒÔÉÔºóÖ´ÐС£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃSystemdºÍCrontabÀ´ÉèÖÃ׼ʱʹÃüµÄÓÅÏȼ¶ £¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£

SystemdµÄ׼ʱʹÃüÓÅÏȼ¶ÉèÖÃ

SystemdÊÇÏÖ´úLinuxϵͳÖг£ÓõÄϵͳºÍЧÀÍÖÎÀíÆ÷ £¬Ëü¿ÉÒÔÓÃÓÚÖÎÀíºÍ¿ØÖÆÖÖÖÖʹÃü¡£ÔÚSystemdÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÐÞ¸Ä׼ʱʹÃüµÄTimerÉèÖÃÎļþÀ´ÉèÖÃʹÃüµÄÓÅÏȼ¶¡£

Ê×ÏÈ £¬·­¿ªTerminal²¢Ê¹ÓÃÎı¾±à¼­Æ÷½¨ÉèÒ»¸öеÄ׼ʱʹÃüÉèÖÃÎļþ £¬ÀýÈç mytimer.timer£º

sudo nano /etc/systemd/system/mytimer.timer

µÇ¼ºó¸´ÖÆ

ÔÚÉèÖÃÎļþÖÐ £¬ÎÒÃÇÐèÒª½ç˵׼ʱʹÃüµÄÖ´ÐÐʱ¼äÒÔ¼°ÓÅÏȼ¶¡£ÒÔÏÂÊÇÒ»¸öʾÀýÉèÖÃÎļþµÄÄÚÈÝ£º

[Unit]
Description=MyTimer

[Timer]
OnCalendar=*-*-* *:*:00
AccuracySec=1s
Persistent=true

[Install]
WantedBy=multi-user.target

µÇ¼ºó¸´ÖÆ

ÔÚ [Timer] ²¿·ÖÖÐ £¬ÎÒÃÇͨ¹ý AccuracySec ²ÎÊýÀ´Ö¸¶¨Ê¹ÃüµÄÓÅÏȼ¶ £¬µ¥Î»ÎªÃë¡£½ÏСµÄÖµÌåÏֽϸߵÄÓÅÏȼ¶¡£±ðµÄ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýµ÷½â OnCalendar ²ÎÊýÀ´½ç˵ʹÃüµÄÖ´ÐÐʱ¼ä £¬Õâ¸ö²ÎÊýÖ§³ÖÖÖÖÖʱ¼äÃûÌá£

ÉúÑIJ¢¹Ø±ÕÎļþºó £¬ÖØмÓÔØSystemdÉèÖÃÎļþ £¬²¢Æô¶¯ÎÒÃǵÄ׼ʱʹÃü£º

sudo systemctl daemon-reload
sudo systemctl start mytimer.timer

µÇ¼ºó¸´ÖÆ

ÏÖÔÚ £¬ÎÒÃǵÄ׼ʱʹÃüÒѾ­ÀÖ³ÉÉèÖà £¬²¢ÇÒƾ֤ÓÅÏȼ¶¾ÙÐÐÁ˵÷Àí¡£

CrontabµÄ׼ʱʹÃüÓÅÏȼ¶ÉèÖÃ

CrontabÊÇÒ»¸öĬÈÏ×°ÖÃÔÚ´ó´ó¶¼LinuxϵͳÉϵÄ׼ʱʹÃü¹¤¾ß¡£Í¨¹ý±à¼­CrontabÉèÖÃÎļþ £¬ÎÒÃÇ¿ÉÒÔÉèÖúÍÖÎÀí׼ʱʹÃü¡£

ÒªÉèÖÃʹÃüµÄÓÅÏȼ¶ £¬ÎÒÃÇ¿ÉÒÔʹÓà nice ÏÂÁîÀ´ÔËÐÐʹÃü £¬²¢ÔÚÏÂÁîÇ°Ìí¼ÓÏìÓ¦µÄ²ÎÊý¡£¸Ã²ÎÊýÌåÏÖʹÃüµÄÓÅÏȼ¶ £¬½ÏСµÄÖµÌåÏֽϸߵÄÓÅÏȼ¶¡£

ͨ¹ýÒÔÏ°취ÔÚCrontabÖÐÉèÖÃ׼ʱʹÃüµÄÓÅÏȼ¶£º

Ê×ÏÈ £¬·­¿ªTerminal²¢ÊäÈëÒÔÏÂÏÂÁîÒԱ༭Ŀ½ñÓû§µÄCrontabÉèÖÃÎļþ£º

crontab -e

µÇ¼ºó¸´ÖÆ

ÔÚÎļþÖÐ £¬½ç˵׼ʱʹÃüµÄÖ´ÐÐʱ¼äºÍÏÂÁî¡£ÒÔÏÂÊÇÒ»¸öʾÀýµÄCrontabÉèÖÃÎļþÄÚÈÝ£º

* * * * * nice -n -10 /path/to/command

µÇ¼ºó¸´ÖÆ

ÔÚÏÂÁîÇ° £¬ÎÒÃÇʹÓà nice -n -10 É趨ÁËʹÃüµÄÓÅÏȼ¶Îª -10 £¬ÌåÏֽϸߵÄÓÅÏȼ¶¡£±ðµÄ £¬Ö´ÐÐʱ¼äµÄ½ç˵ÈÔÈ»×ñÕÕCrontabµÄÓï¹æÔòÔò¡£

ÉúÑIJ¢¹Ø±ÕÎļþºó £¬Cron½«»áƾ֤ÎÒÃÇÉèÖõÄÓÅÏȼ¶À´µ÷Àí׼ʱʹÃü¡£

×ÛÉÏËùÊö £¬Í¨¹ýSystemdºÍCrontab £¬ÎÒÃÇ¿ÉÒÔÔÚLinuxϵͳÖÐÉèÖÃ׼ʱʹÃüµÄÓÅÏȼ¶¡£Ê¹ÓÃSystemdʱ £¬ÐÞ¸ÄTimerÉèÖÃÎļþ²¢ÉèÖà AccuracySec ²ÎÊýÀ´½ç˵ʹÃüµÄÓÅÏȼ¶¡£¶øÔÚCrontabÖÐ £¬¿ÉÒÔͨ¹ý nice ÏÂÁîÀ´É趨ʹÃüµÄÓÅÏȼ¶¡£ÎÞÂÛʹÓÃÄÄÖÖÒªÁì £¬ÓÅÏȼ¶½ÏСµÄʹÃü½«»á¸üÓÅÏÈÖ´ÐС£ÒÔÉÏÊÇÁ½ÖÖÒªÁìµÄÏêϸ´úÂëʾÀý £¬Ï£Íû¶ÔÄãÓÐËù×ÊÖú¡£

ÒÔÉϾÍÊÇÔõÑùʹÓÃSystemdºÍCrontabÔÚLinuxϵͳÖÐÉèÖÃ׼ʱʹÃüµÄÓÅÏȼ¶µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ