Is it OK for me to set up the crontab task?

Source: Internet
Author: User
Keywords Php crontab
Tags log log
I set up two scheduled tasks, which are scheduled to restart the service, as follows:

[root@iZ94r80gdghZ tanteng]# crontab -l# 系统计划任务* */1 * * * service mariadb restart >> /home/tanteng/crontab.log* * */1 * * service php70-php-fpm restart >> /home/tanteng/crontab.log

I just put the command statements in the back of the scheduled task can be, these commands in the machine can be run, while the output recorded to the log log, but the log log does not have any content, do not know that the program is not effective, so write right?

Reply content:

I set up two scheduled tasks, which are scheduled to restart the service, as follows:

[root@iZ94r80gdghZ tanteng]# crontab -l# 系统计划任务* */1 * * * service mariadb restart >> /home/tanteng/crontab.log* * */1 * * service php70-php-fpm restart >> /home/tanteng/crontab.log

I just put the command statements in the back of the scheduled task can be, these commands in the machine can be run, while the output recorded to the log log, but the log log does not have any content, do not know that the program is not effective, so write right?

Two places you need to be aware of.
1 The service command is accessible in crontab
2 Through the restart way, the application produces the log can really record to the specified file?

1th question can be viewed /var/log/messages and /var/spool/mails/username log judged
The 2nd question is good to solve, direct command line service mariadb restart > ~/mariadb.log , then connect to database, do query (generate log), and then view this file, but actually I guess there should be no.

LS says it's basically comprehensive.

Crontab, generic or when you are unsure, the command is packaged directly into an executable file and then directly crontab the executable.

Service command operation, General MARIADB and the like to go back to the configuration file, so the actual DB log output will be in the location specified in the configuration file

Service xxx Restart >> xxx.log, this inside Xxx.log is just a short message of whether the output is successful or not

Check the crontab log to see if it has been executed
Star/1 This notation superfluous, write stars

1, check the crontab log, see whether this two command execution, (execution does not necessarily succeed)
2, simple judgment, through the process of the PID judgment, whether the implementation of success, are restart command, smooth restart, the PID will change

1L basically said it.
I also said a few points:

1.直接先测试命令,看是否能使用,例如你上面的:service mariadb restart >> /home/tanteng/crontab.log2.把命令调到 * * * * * 每分钟先做一个测试,可以的话,再修改命令。

Using full path execution commands in crontab

* */1 * * * /user/lib/user/bin/service mariadb restart >> /home/tanteng/crontab.log* * */1 * * /user/lib/user/bin/service php70-php-fpm restart >> /home/tanteng/crontab.log
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.