[LINUX] Setting to output the log of cron execution

Introduction

I set to output the log of cron execution to a log file.

environment

Ubuntu 16.04.5 LTS

procedure

Open this file.

vi /etc/rsyslog.d/50-default.conf

By default, this line should be commented, so uncomment and update.

cron.*                         /var/log/cron.log

However, it could not be updated because it was Read Only. Change the permissions so that you can write.

sudo chmod 646 /etc/rsyslog.d/50-default.conf
(Change before)-rw-r--r--
(After change)-rw-r--rw-

The cron log is output by rsyslog. The rsyslog service must be restarted for the above settings to take effect.

service rsyslog restart

Make sure that the service is started just in case.

service --status-all | grep rsyslog

The log will be output here. rsyslog will write the cron log for you. A new cron.log is created when the first log is written to cron.log.

/var/log/cron.log

reference

https://qiita.com/skyfish20ch/items/46db70e1ff88166ead87

Instead of writing the cron log with rsyslog, make the command executed by cron the standard output log.

Add the following two lines with ** crontab -e **.

1 12 * * * cd $HOME && date "+\%Y/\%m/\%d \%H:\%M:\%S" >> ./syori01.log
2 12 * * * cd $HOME && /usr/local/rbenv/shims/ruby syori01.rb >> ./syori01.log

Commentary

At 12:01, write the system date and time to syori01.log, and then at 12:02, execute the ruby program called syori01.rb and output it to syori01.log as standard. The caveat is that if you specify a date in cron, it won't work unless you escape the%.

・ To find the place where ruby is stored, do ** which ruby **. -This process is executed in the Home directory.

reference

https://qiita.com/doitnow420@github/items/70bc148d782e96492282

Recommended Posts

Setting to output the log of cron execution
Take the execution log of Celery
The inaccuracy of Tensorflow was due to log (0)
From the introduction of pyethapp to the execution of contract
I made a tool to estimate the execution time of cron (+ PyPI debut)
I want to grep the execution result of strace
[python] option to turn off the output of click.progressbar
Filter the output of tracemalloc
Set the output destination of the execution result to Vim started as a modeless window
Switch the setting value of setting.py according to the development environment
Keras I want to get the output of any layer !!
I tried to output the access log to the server using Node.js
How to overwrite the output to the console
Supplement to the explanation of vscode
I want to record the execution time and keep a log.
How to change the log level of Azure SDK for Python
I want to output the beginning of the next month with Python
Output the contents of ~ .xlsx in the folder to HTML with Python
How to output the output result of the Linux man command to a file
[Python3] Define a decorator to measure the execution time of a function
How to monitor the execution status of sqlldr with the pv command
I want to output to the console coolly
The story of trying to reconnect the client
Script to change the description of fasta
10 methods to improve the accuracy of BERT
How to check the version of Django
The story of adding MeCab to ubuntu 16.04
Output Python log to console with GAE
Build the execution environment of Jupyter Lab
Setting to debug test by entering the contents of the library with pytest
How to get colored output to the console
The story of pep8 changing to pycodestyle
Output user information etc. to Django log
Visualize the export data of Piyo log
Introduction to Scapy ① (From installation to execution of Scapy)
How to pass the execution result of a shell command in a list in Python
A programming beginner tried to find out the execution time of sorting etc.
To output a value even in the middle of a cell with Jupyter Notebook
[NNabla] How to get the output (variable) of the middle layer of a pre-built network
How to count the number of elements in Django and output to a template
Change Flask's log settings (dictConfig) to output logs other than the root logger
Output the number of CPU cores in Python
Log in to the remote server with SSH
How to find the area of the Voronoi diagram
Prepare the execution environment of Python3 with Docker
Combinatorial optimization to find the hand of "Millijan"
[Ansible installation procedure] From installation to execution of playbook
Set the range of active strips to the preview range
I tried to touch the API of ebay
I tried to correct the keystone of the image
Change the decimal point of logging from, to.
Read the output of subprocess.Popen in real time
Output python log to both console and file
How to erase the characters output by Python
Output in the form of a python array
To get the path of the currently running python.exe
I want to customize the appearance of zabbix
Use pygogo to get the log in json.
Try to simulate the movement of the solar system
The story of moving from Pipenv to Poetry
Create a command to get the work log