作業の自動化 cron  

作業の自動化 cron

システムが起動すると、/usr/lib/cronというデーモンが自動的に動作します。これは、1分間に一度自動的に起き出して、設定ファイルに指示された時刻になっていれば、指定されたジョブを実行します。
 
$ ps -ef | grep cron
    root   195     1   0 14:22:49 ?           0:00 /usr/sbin/cron

Solarisのcronは、ユーザー毎に独自の設定を持つことができます。cronから起動されるジョブは、それを登録したユーザーの権限で実行されます。デフォールト状態で、root権限で実行されるジョブを見てみます。
登録されているジョブは、'crontab -l ユーザ名'というコマンドで見ることができます。
各権限でのcron設定ファイルは/var/spool/cron/crontabs/に登録されています。

$ su -
Password:
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
# crontab -l
#ident  "@(#)root       1.21    04/03/23 SMI"
#
# The root crontab should be used to perform accounting data collection.
#
#
10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
#
# The rtc command is run to adjust the real time clock if and when
# daylight savings time changes.
#
1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1
#10 3 * * * /usr/lib/krb5/kprop_script ___slave_kdcs___
#

設定内容は、左から順に

 分 (0〜59)、時 (0〜23)、日 (1〜31)、月 (1〜12)、曜日 (0(日)〜6(土))、コマンド

になります。
'*'はそのフィールドの値が何でも一致することを意味します。

従って、上記のrootのジョブとしてデフォールトで登録されているものは、次のタイミングで実行されることになります。
 
タイミング コマンド 処理内容
毎日3時10分 /usr/sbin/logadm  
日曜日3時15分 /usr/lib/fs/nfs/nfsfind  
毎日3時30分 [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean  
毎日2時1分 [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1  


■ cronの設定ファイル

# pwd
/var/spool/cron/crontabs
# ls -l
合計 10
-rw-------   1 root     sys          190 11月 15日  19:16 adm
-r--------   1 root     root         452 11月 15日  19:47 lp
-rw-------   1 root     root         482 12月  6日  18:46 root
-rw-------   1 root     sys          308 11月 15日  19:31 sys
-r--------   1 root     sys          404 11月 15日  19:46 uucp
# cat root
#ident  "@(#)root       1.21    04/03/23 SMI"
#
# The root crontab should be used to perform accounting data collection.
#
#
10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
#
# The rtc command is run to adjust the real time clock if and when
# daylight savings time changes.
#
1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1
#10 3 * * * /usr/lib/krb5/kprop_script ___slave_kdcs___
#



 


 【参考URL】
 cron の設定ガイド
  http://www.express.nec.co.jp/linux/tech/knowledge/system/crond.html



iota    _