I have set two scheduled tasks to regularly restart the Service, as shown in the following code: {code ...} can I directly place command statements after a scheduled task? These commands can be run on the local machine and the output is recorded in the log, but the log does not have any content, I do not know this plan... I have set two scheduled tasks to regularly restart the Service, as shown below:
[Root @ iZ94r80gdghZ tanteng] # crontab-l # system scheduled task **/1 *** service mariadb restart>/home/tanteng/crontab. log php70-php-fpm restart>/home/tanteng/crontab. log
Can I directly place command statements after a scheduled task? These commands can be run on the local machine and the output is recorded in the log, but the log does not have any content, I don't know if this scheduled task has taken effect. Is this correct?
Reply content:
I have set two scheduled tasks to regularly restart the Service, as shown below:
[Root @ iZ94r80gdghZ tanteng] # crontab-l # system scheduled task **/1 *** service mariadb restart>/home/tanteng/crontab. log php70-php-fpm restart>/home/tanteng/crontab. log
Can I directly place command statements after a scheduled task? These commands can be run on the local machine and the output is recorded in the log, but the log does not have any content, I don't know if this scheduled task has taken effect. Is this correct?
What you need to pay attention to in two places
1. Whether the service command can be accessed in crontab
2. Through restart, can application logs be recorded to the specified file?
1st questions can be viewed/var/log/messagesAnd/var/spool/mails/usernameLog judgment
2nd problems are well solved, and direct command lineservice mariadb restart > ~/mariadb.log, Connect to the database, perform queries (generate logs), and then view the file, but I guess it should not.
LS is basically comprehensive.
In crontab, when it is common or you are not sure about it, the command is directly packaged into an executable file, and then the crontab executable file is ready.
For service command operations, mariadb and the like usually go back to the configuration file, so the actual db log output will be in the location specified by the configuration file
Service xxx restart> xxx. log, in which xxx. log only outputs very short information such as whether the startup is successful.
Check the crontab log to see if it has been executed
The star/1 statement adds one more way to writing a star.
1. Check the crontab log to see whether the two commands are executed. (The execution may not be successful)
2. Simple judgment: The pid of the process determines whether the execution is successful. It is a restart command. After a smooth restart, the pid will change.
1L is basically mentioned.
Let me also talk about the following points:
1. test the command to check whether it can be used. For example, you can use service mariadb restart>/home/tanteng/crontab. log2. tune the command to *** and perform a test every minute. If you can, modify the command.
Use full path to execute 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