LoginSignup
0
1

More than 5 years have passed since last update.

cron で、stderr への出力をログに入れる方法

Last updated at Posted at 2017-11-21

次のプログラムをcron で実行した時のログの取り方です。

cron_test.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#   cron/cron_test.py
#                   Nov/22/2017
#
# ----------------------------------------------------------------
import sys
import datetime
#
# ----------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
time_aa = datetime.datetime.now()
#
print (time_aa)
#
sys.stderr.write("*** 終了 ***\n")
#
# ----------------------------------------------------------------

標準出力だけをログに入れる場合

*/2 * * * * /home/uchida/cron/cron_test.py > /tmp/cron_a.log

ログ出力

cron_a.log
2017-11-22 08:32:01.268014

標準出力と、stderr をログに入れる場合

*/2 * * * * /home/uchida/cron/cron_test.py > /tmp/cron_b.log 2>&1

ログ出力

cron_b.log
*** 開始 ***
*** 終了 ***
2017-11-22 08:27:01.748117
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1