I tried using cron

A rough explanation of the basics

--cron --- Regularly executed daemon --crontab --- Schedule cron

Execution environment Linux Mint (19.1 Tessa), EC2 (Amazon Linux2)

You can display the current settings with the following command

$crontab -l

I ran the above command in docker and on a Mac, but the command didn't exist (* I checked it later and found it on the Mac ... the display was a little different, so it seems to be a mistake). For the time being, I tried it on a Linux Mint (19.1 Tessa) PC. If crontab can be used and it is not set, it will be displayed as follows. corabtab_-l.png You will be able to edit the settings with the following command. At first, you will be asked to specify an editor. (I set it to Vim this time. Nano was recommended)

$crontab -e

crontab_-e.png

Commands are minutes, hours, days, months, days of the week, commands Describe in the order of, and leave a half-width space. The following is the setting to run the shell every 10 minutes

*/10 * * * * /home/user/test.sh

Command to check cron execution log

--For Linux Mint

grep CRON /var/log/syslog

--For EC2

sudo grep CRON /var/log/cron

Trouble encountered this time and how to deal with it

Trouble ① Error No MTA installed, discarding output

Nothing happened even if I set it, so when I checked the execution log, the following display was displayed. cron_log_err.png After investigating, it is said that Ubuntu and Ubuntu are events that occur in the base Linux Mint.

Installing postfix fixed the above error.

sudo aptitude install postfix

Trouble ② Shell permissions

I solved the problem (1), but the shell didn't work at all. When I checked the file permissions with the ls -l command, it was `` `-rw-rw-r --```.

Granted execute permission. (Since the authority is given to move it for the time being, please change it if necessary)

chmod +x test.sh

The shell worked fine.

Supplement

By the way, I just wanted to check the operation of cron, so I used a simple command as follows.

echo "test cron1" >> /home/owner/aaa.txt

Recommended Posts

I tried using cron
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried using aiomysql
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
I tried using openpyxl
I tried using Ipython
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried using folium
I tried using jinja2
I tried using folium
I tried using time-window
[I tried using Pythonista 3] Introduction
I tried using easydict (memo).
I tried face recognition using Face ++
I tried using Random Forest
I tried using Amazon Glacier
I tried using git inspector
[Python] I tried using OpenPose
I tried using magenta / TensorFlow
I tried using AWS Chalice
I tried using Slack emojinator
I tried using Rotrics Dex Arm # 2
I tried using Rotrics Dex Arm
I tried using GrabCut of OpenCV
I tried using Thonny (Python / IDE)
I tried server-client communication using tmux
I tried reinforcement learning using PyBrain
I tried deep learning using Theano
Somehow I tried using jupyter notebook
[Kaggle] I tried undersampling using imbalanced-learn
I tried shooting Kamehameha using OpenPose
I tried using the checkio API
[Python] I tried using YOLO v3
I tried asynchronous processing using asyncio
I tried scraping
I tried PyQ
I tried AutoKeras
I tried papermill
I tried django-slack
I tried Django
I tried spleeter
I tried cgo
I tried using Azure Speech to Text.
I tried using Twitter api and Line api
I tried playing a ○ ✕ game using TensorFlow
I tried using YOUTUBE Data API V3
[Kaggle] I tried ensemble learning using LightGBM
I tried using PyEZ and JSNAPy. Part 2: I tried using PyEZ