crontab出力方法

デフォルトでは標準出力・標準エラー出力はメール送信される

送信先を指定

root@hostname:/home/shimizu# crontab -uroot -l
MAILTO=shimizu.test0@gmail.com
* * * * * echo "cron test"

2016-01-01_164444

日付をつけてファイル出力

root@hostname:/home/shimizu# crontab -uroot -l
* * * * * echo "cron test" >> /var/log/crontab/`date +\%Y\%m\%d`.log 2>&1

複数プログラムのログを出力する

root@hostname:/home/shimizu# crontab -uroot -l
LOGDIR="/var/log/crontab"
* * * * * echo "cron test1" >> $LOGDIR/`date +\%Y\%m\%d`.1.log 2>&1
* * * * * echo "cron test2" >> $LOGDIR/`date +\%Y\%m\%d`.2.log 2>&1

syslogに送る

root@hostname:/home/shimizu# crontab -uroot -l
* * * * * echo "cron test" 2>&1 | logger -t crontab -p cron.info

root@hostname:/home/shimizu# tail -f /var/log/syslog
Jan  1 17:17:01 hostname CRON[3070]: (root) CMD (echo "cron test" 2>&1 | logger -t crontab -p cron.info)
Jan  1 17:17:01 hostname crontab: cron test
...

参考URL

cron力をつけよう!全てのcrontab入門者に贈る9個のテクニック
cron で > /dev/null して椅子を投げられないための3つの方法