[LINUX] Job Scheduling @ Study Memo

Introduction

On Linux, jobs that run regularly are `cron``` One-time job reservations can be scheduled using the ```at command `! System management costs can be reduced by automating the tasks that are performed on a regular basis.

cron cron consists of `crond```, which is a daemon that manages schedules (a process that runs on Unix-like multitasking operating systems), and crontab command , which edits scheduling. The crond daemon checks the crontab file every minute and will run any jobs that you want to run! The crontab file is located under the / var / spool / cron directory and cannot be edited directly with an editor. So use the crontab command ```.

cron job settings

$ crontab -e

You can edit it when crontab opens in your default editor. Edit and save, then finish.

Check the list of reserved jobs

$ crontab -l

Delete all reserved cron jobs

$ crontab -r

Format crontab file

 Minutes, hours, days, months, days of the week commands

For fields,

--Min: Integer from 0-59 --Hour: Integer from 0-23 --Day: Integer from 1-31 --Month: An integer from 1-12, or a character string such as Sun, Mon, etc. --Command: Command to execute

Example crontab file (run program daily at 22:30)

 Dairy Backup
30 22 * * * /usr/local/bin/backup

There is no need to restart and the job will run automatically!

at command

The at command `` `runs a one-time schedule, whereas cron runs the job repeatedly on a regular basis. at command```The at daemon must be running to perform scheduling by!

Format when reserving a job with the at command

at hh:mm MMDDYY

For example, if you book to run at 22:30 on January 28, 2020 ...

$ at 22:30 012820

The at command inputs commands interactively, so at>When prompted, specify the command.

$ at 22:30 012820
at> /usr/local/sbin/backup
at> ^D

When specifying a command in a file, write the command in the file (jobs file this time) and write it.

$ at -f jobs 22:30

Check the list of reserved jobs

$ at -l

Or

$ atq

Delete reserved job (specify job ID)

$ at -d 3

Or

$ atrm 3

cron access control

--Write a user who is allowed to use cron in /etc/cron.allow --In /etc/cron.deny, describe the user who refuses to use cron.

If there is ** /etc/cron.allow **, only the users described there can use cron, but if not, it refers to ** /etc/cron.deny ** and is not described there. All users can use cron.

access control of at

--In /etc/at.allow, describe the users who are allowed to use at. --In / etc / at / deny, describe the user who refuses to use at.

If there is ** /etc/at.allow **, only the users described there can use at, but if not, it refers to ** / etc / at / deny ** and is not described there. All users can use at. Without either, only the root user can use at.

reference

Linux textbook LPIC Level 1 Version 5.0 compatible

Recommended Posts

Job Scheduling @ Study Memo
LPIC101 study memo
Shell script @ study memo
Interval scheduling learning memo ~ by python ~
Python & Machine Learning Study Memo: Environment Preparation
[Online] Everyone's Python study session # 55 Rough memo
[Study memo] OAuth2 integration between django projects
Python & Machine Learning Study Memo ③: Neural Network
Study memo 1_eclipse (python) download, python execution, OpenPyXL download
Python & Machine Learning Study Memo ④: Machine Learning by Backpropagation
Python & Machine Learning Study Memo ⑥: Number Recognition