[LINUX] How to use cron (personal memo)

I set up cron on the server at work. Write the information you need to a minimum.

** What I want to do: ** Run the Perl script `` `/foo/bar/baz.pl``` every morning at 5am ** Prerequisites: ** Linux for OS, bash for shell

What I did is as follows (excluding trial and error).

EDITOR confirmation and settings

Log in to the server (Linux). Check the EDITOR environment variable.

$ echo $EDITOR

It was empty. If you try to edit crontab here, vi will start. I only know how to use Emacs. Try starting Emacs.

$ emacs
There is no such command Error message

It was no good. You can install Emacs, but I'll use nano here. nano is usually installed on Linux and is an editor that works even if you don't know how to use it.

$ EDITOR=nano
$ export EDITOR
$ echo $EDITOR
nano

I was able to set nano safely.

Check the time zone

Try using the command `` `date``` to know the current time.

$ date
Fri Aug 14 08:43:43 UTC 2020

It turns out that it is UTC (the same as London time at the time of World Agreement). Check the time difference site to find out what time 5 am in Japan is in UTC.

https://www.jisakeisan.com/

It turned out to be 20:00.

List crontab

Finally crontab settings. -lA list of crons that are currently set as an option.

$ crontab -l

Nothing came out so I knew no one had set anything.

Editing crontab

Editing is the -e option (Edit). If you run it yourself (the logged-in user), you do not need to set the `` `-u``` option.

$ crontab -e

The nano set in $ EDITOR just started.

crontab settings

To run /foo/bar/baz.pl at 5am every morning:

0 20 * * * /foo/bar/baz.pl

You can use nano, but Ctrl + O writes out the file (write Out) and Ctrl + X exits nano (eXit). You don't have to remember how to use nano because it is displayed at the bottom of the screen.

that's all.

Reference material

How to set up cron https://qiita.com/hikouki/items/e744b3a4d356d2af12cf

Creating and editing crontab files https://docs.oracle.com/cd/E19253-01/819-0379/sysrescron-24589/index.html

** (End of this section) **

Recommended Posts

How to use cron (personal memo)
[Memo] How to use Google MµG
How to use MultiIndex (personal memorandum)
[Memo] How to use BeautifulSoup4 (1) Display html
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
How to use Seaboan
How to use image-match
How to use shogun
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use Pyenv
How to use list []
How to use python-kabusapi
How to use OptParse
How to use return
How to use dotenv
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
How to use Qt Designer
How to use search sorted
[gensim] How to use Doc2Vec
python3: How to use bottle (2)
Understand how to use django-filter
How to use the generator
[Python] How to use list 1
How to use FastAPI ③ OpenAPI
How to use Python argparse
How to use IPython Notebook
How to use Pandas Rolling
[Note] How to use virtualenv
How to use redis-py Dictionaries
Python: How to use pydub
[Python] How to use checkio
[Go] How to use "... (3 periods)"
How to use Django's GeoIp2
[Python] How to use input ()
How to use the decorator
[Introduction] How to use open3d
How to use Python lambda
How to use Jupyter Notebook
[Python] How to use virtualenv