尊龙凯时人生就是搏

ÔõÑùʹÓÃSystemdºÍCrontabÔÚLinuxϵͳÖÐʵÏÖ׼ʱʹÃüÈÕÖ¾¼Í¼

ÔõÑùʹÓÃSystemdºÍCrontabÔÚLinuxϵͳÖÐʵÏÖ׼ʱʹÃüÈÕÖ¾¼Í¼

ÔÚLinuxϵͳÖУ¬×¼Ê±Ê¹ÃüÊǷǾ­³£¼ûµÄÐèÇóÖ®Ò»¡£ÎªÁËÄܹ»¸üºÃµØÖÎÀíºÍ¼à¿Ø׼ʱʹÃü£¬ÎÒÃǾ­³£ÐèÒª¼Í¼׼ʱʹÃüµÄÖ´ÐÐÇéÐκÍÈÕÖ¾ÐÅÏ¢¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃSystemdºÍCrontabÀ´ÊµÏÖ׼ʱʹÃüµÄÈÕÖ¾¼Í¼£¬²¢ÌṩÏêϸµÄ´úÂëʾÀý¡£

Ò»¡¢Systemd ׼ʱʹÃüÈÕÖ¾¼Í¼

Systemd ÊÇÏÖÔÚÖ÷Á÷µÄ Linux ϵͳÖÎÀí¹¤¾ß£¬¿ÉÒÔÖÎÀíϵͳЧÀͺÍÊØ»¤Àú³Ì¡£ÎÒÃÇ¿ÉÒÔͨ¹ý±àд Systemd ЧÀ͵¥Î»ÎļþÀ´ÊµÏÖ׼ʱʹÃüµÄÈÕÖ¾¼Í¼¡£

ÒÔÏÂÊÇÒ»¸öʾÀýµÄ Systemd ЧÀ͵¥Î»Îļþ£¬ÓÃÓڼͼ׼ʱʹÃüµÄÈÕÖ¾£º

[Unit]

Description=׼ʱʹÃüÈÕÖ¾¼Í¼ЧÀÍ

[Service]

Type=oneshot

ExecStart=/usr/bin/bash -c “Ö´ÐÐ׼ʱʹÃüµÄÏÂÁî >> /var/log/task.log”

[Install]

WantedBy=default.target

ÉÏÊöʾÀýÖУ¬ÎÒÃǽç˵ÁËÒ»¸öÃû³ÆΪ “׼ʱʹÃüÈÕÖ¾¼Í¼ЧÀÍ” µÄ Systemd ЧÀÍ¡£ÔÚ [Service] ½ÚµãÖУ¬ÎÒÃÇÉèÖÃÁË Type Ϊ oneshot£¬ÌåÏÖ¸ÃЧÀÍÖ»»áÖ´ÐÐÒ»´Î¡£È»ºóÎÒÃÇͨ¹ý ExecStart ÉèÖÃÁËÖ´ÐеÄÏÂÁ½«×¼Ê±Ê¹ÃüµÄÈÕÖ¾ÐÅÏ¢Êä³öµ½ /var/log/task.log ÎļþÖС£

ΪÁËÆô¶¯ºÍÖÎÀí¸ÃЧÀÍ£¬ÎÒÃÇÐèÒª½«ÒÔÉÏÄÚÈÝÉúÑÄΪһ¸öÒÔ “.service” ×îºóµÄÎļþ£¬ÀýÈç “task-logger.service”£¬²¢½«¸ÃÎļþ°²ÅÅÔÚ /etc/systemd/system/ Ŀ¼Ï¡£È»ºóʹÓÃÒÔÏÂÏÂÁîÀ´Æô¶¯ºÍÖÎÀí¸ÃЧÀÍ£º

sudo systemctl start task-logger.service // Æô¶¯Ð§ÀÍ

sudo systemctl enable task-logger.service // ÉèÖÿª»ú×ÔÆô¶¯

sudo systemctl status task-logger.service // Éó²éЧÀÍ״̬

ÒÔÉÏ°ì·¨Íê³Éºó£¬×¼Ê±Ê¹ÃüµÄÖ´ÐÐЧ¹û¾Í»á±»¼Í¼ÔÚ /var/log/task.log ÎļþÖУ¬Àû±ãÎÒÃÇËæʱÉó²é¡£

¶þ¡¢Crontab ׼ʱʹÃüÈÕÖ¾¼Í¼

Crontab ÊÇÒ»¸öÓÃÓÚÔÚָ׼ʱ¼ä¾àÀëÄÚÖ´ÐÐʹÃüµÄ¹¤¾ß¡£Æ¾Ö¤ÐèÒª£¬ÎÒÃÇ¿ÉÒÔÍŽáʹÓà Crontab ºÍÈÕÖ¾¼Í¼ÏÂÁîÀ´ÊµÏÖ׼ʱʹÃüµÄÈÕÖ¾¼Í¼¡£

ÒÔÏÂÊÇÒ»¸öʾÀýµÄ Crontab ʹÃü£¬ÓÃÓڼͼ׼ʱʹÃüµÄÈÕÖ¾£º

/usr/bin/bash -c “Ö´ÐÐ׼ʱʹÃüµÄÏÂÁî >> /var/log/task.log”

ÉÏÊöʾÀýÖУ¬ÎÒÃÇʹÓÃÁËÐǺţ¨*£©À´ÌåÏÖÿ·ÖÖÓ¶¼Ö´ÐиÃʹÃü¡£È»ºóÎÒÃÇͨ¹ýÖ´ÐÐÏÂÁ׼ʱʹÃüµÄÈÕÖ¾ÐÅÏ¢Êä³öµ½ /var/log/task.log ÎļþÖС£

ΪÁËÉèÖøÃ׼ʱʹÃü£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî±à¼­ Crontab£º

crontab -e

È»ºó½«ÒÔÉÏÉèÖø´ÖƵ½ÎļþÖУ¬²¢ÉúÑÄÍ˳ö¼´¿É¡£Ö®ºó£¬×¼Ê±Ê¹ÃüµÄÖ´ÐÐЧ¹û¾Í»á±»¼Í¼ÔÚ /var/log/task.log ÎļþÖС£

×ܽá

ͨ¹ýʹÓà Systemd ºÍ Crontab ¹¤¾ß£¬ÎÒÃÇ¿ÉÒÔÀû±ãµØʵÏÖ׼ʱʹÃüµÄÈÕÖ¾¼Í¼¡£ÔÚ Systemd ÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ý±àдЧÀ͵¥Î»ÎļþÀ´ÊµÏÖÈÕÖ¾¼Í¼¡£¶øÔÚ Crontab ÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÉèÖÃ׼ʱ´¥·¢Ê¹Ãü²¢Ö´ÐÐÏìÓ¦ÏÂÁîÀ´ÊµÏÖÈÕÖ¾¼Í¼¡£

¹ØÓÚ¿ª·¢Õ߶øÑÔ£¬ºÏÀíʹÓÃ׼ʱʹÃüÈÕÖ¾¼Í¼¹¦Ð§¿ÉÒÔ¸üºÃµØ¼à¿ØºÍÖÎÀí׼ʱʹÃü£¬Ìá¸ßϵͳµÄÎȹÌÐÔºÍÔËÐÐЧÂÊ¡£Í¬Ê±£¬ÈÕÖ¾¼Í¼ҲΪÎÒÃǺóÐøµÄÎÊÌâÅŲéÌṩÁ˱㵱¡£

Ï£Íû±¾ÎĶÔÄúÄܹ»ÓÐËù×ÊÖú£¡

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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