Questions about using crontab to modify database tables in linux

Source: Internet
Author: User
In linux, if you use crontab to modify the database and table, choose Linux Enterprise Application> Linux server application. For more information, see the following. My usage is as follows:

1. Log On with the yz user.

2. Run the crontab-e command to open the file. Write "0 1 **** chg_date>/home/yz. log "indicates that at every morning, the chg_date program is called to modify the system date and put the output in the program into yz. log File.

3. Run the ": x" command to save the disk and exit.

According to my understanding, "when the changes made to crontab are saved, the crontab file will be saved according to the user name and written into the file/var/spool/cron/username. The cron daemon checks the/etc/crontab file, the etc/cron. d/directory, and the changes in the/var/spool/cron directory every minute. If changes are found, they are loaded into the memory. In this way, when a crontab file changes, you do not have to restart the daemon ." So I was too lazy to test it. The next day I went to work and checked the database table. It was the date of yesterday.

This time we found a new command: "/etc/rc. d/init. d/crond restart", which can be used to restart the cron service. So I modified the crontab file and changed the time every two minutes. Wait for a while and check the database table. The changes remain unchanged.

I have no patience, so I started to ask people in the office :"#@*#...... @?" This time I was surprised to hear from my colleagues: "You can use crontab instead of restarting it ." At last, Monitor provided a solution. Since it is useless to create a crontab file under the yz user, it was created under the root user.

Therefore, I log on again as a root user and use crontab-e to write: "*/2 ***** (su-yz-c chg_date 2>/home/yz. log )". After waiting for a few minutes, the date of the database table remains unchanged. It's a bit frustrating. I tried again "/etc/rc. d/init. d/crond restart. A few minutes later, I finally saw the date changed.

The problem is solved, and the question is still in mind:

1. Why is it useless to create a crontab under the yz user? I have seen the/var/spool/cron/yz file.

2. Why must we restart the cron service? In linux, many colleagues can use crontab-e to append the command.
Related Article

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.