ミムの部屋

社内SEが,興味をもったことを書いていきます.

Crontabで定期的にコマンドを打つ(Crontab)

Ubuntu Server 上で今日は,定期的に動かしたい実行ファイルやコマンドを打つようにしたいと思います.
シェルスクリプトで書かれたバックアップの実行ファイルを定期的に実行したい場合は,非常に便利だと思います.
私の環境では,以下のことがありました.
  • crontab -eでは,crontabに記述しても無理であった
  • nano /etc/crontabに記述するとできた
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin


#restart at 7:00
0 7 * * * root shutdown -r now

# 「実行ファイル名1.jar」を7時5分に起動させる.
# 「バックアップファイル名1.log」に標準出力を記述
05 7 * * * root java -jar /home/*****/実行ファイル名1.jar >> /home/*****/バックアップファイル名1.log

# 「実行ファイル名2.jar」を1分毎にに起動させる.
# 「バックアップファイル名2.log」に標準出力を記述 
*/1 * * * * root java -jar /home/*****/実行ファイル名2.jar >> /home/*****/バックアップファイル名2.log