[LINUX] Summary and common errors about cron

Introduction

――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.

What is cron?

--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.)

Commentary

――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?"

Editing the crontab file

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.

Common errors

--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.

Reference site

-One day I suddenly set up cron

-Let's monitor with cron!

-I tried to verify the operation of cron

-IT Glossary cron

-How to use crontab

Finally

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

Summary and common errors about cron
About _ and __
About errors during PyInstaller installation and execution
About Class and Instance
Summary about Python scraping
Summary about Python3 + OpenCV3
About cumprod and cummax
[Python] Memo about errors
About cross-validation and F-number
This and that about pd.DataFrame
Linux (about files and directories)
Adam Paper Summary and Code
About python objects and classes
About Python variables and objects
About LINUX files and processes
About Raid group and LUN
About fork () function and execve () function
About Django's deconstruct and deconstructible
About Python, len () and randint ()
About Python datetime and timezone
About Sharpe Ratio and Sortino Ratio
About Python and regular expressions
About Python and os operations
About http.Handle () and http.NewServeMux (). Handle ()
Python # About reference and copy
About Numpy array and asarray
Summary about pythonic style (1): PEP8
About Python sort () and reverse ()
[Python] A workaround based on common errors and my past experience