――I decided to write this article this time because I recently had the opportunity to relearn about cron, and there were some parts that I didn't fully understand, so I can summarize what I learned this time as an article and reconfirm it myself. Because I wanted to.
--As the title suggests, it is a summary of cron and common errors, so it is an article for beginners rather than experts.
--This content is explained as follows in the cron configuration guide.
Cron is a daemon process for automatically executing jobs (scripts). And when managing a Linux system, there are many jobs that you want to run automatically on a regular basis, such as log rotation and backup. In particular, backups are usually performed in the middle of the night or early in the morning when there is little access from users due to the heavy load on the system.
――I think it's difficult to hear this explanation, but I think there is no problem in recognizing that it will run the specified program at the specified time.
--For example, you can back up as shown in the quote, or restart the web server when it stops. (I think there are many others, but this is just an example.)
――Next, we will proceed from here with a program for those who ask, "I understand what cron is, but how do you actually use it?"
crontab
crontab -l //Check the crontab file
//If there is a file, it will be displayed here.
//If the file does not exist, no crontab for am is displayed.
crontab -e //Editing crontab files
//Running this command will open the vi editor.
--Next, I will write the vi part after crontab --e below.
--The format is the order of the minute, hour, day, and day execution user commands. --The part where the time is not specified is indicated by ***. --The execution user can be omitted.
vi
30 03 * * * /root/apache_process.sh
//Meaning every 3:30 every day/root/apache_process.It will execute sh.
--By editing crontab in this way and specifying an arbitrary file, it will be executed at regular intervals.
――I explained it with a quote at the beginning, but by using this, automatic backup and automatic shutdown are possible.
――If you are interested in reading this article, once you create it yourself, it will be useful for studying and it will be interesting.
--The shell script set by cron may not work. In that case, it is usually the following.
--Is crond running in the first place?
command
/etc/rc.d/init.d/crond status //Check if it works.
/etc/rc.d/init.d/crond start //If it has stopped, start it with this.
-Is there a problem with the permissions of the executable file?
command
ls -al //You can now check your permissions.
chmod +x arbitrary file//Now you can grant execute permission.
//x is the execution. So here, x is given.
--Are there any problems looking at the log?
command
cat /var/log/cron //Now you can check the log.
-One day I suddenly set up cron
-I tried to verify the operation of cron
This time I wrote a summary about cron and an article about common errors. When I research various programs running inside such an OS, it makes me think that it is "deep", but I am keenly aware of my lack of knowledge. In the future, I would like to actively output what I have studied in this way and what I have had the opportunity to learn again.
Recommended Posts