Linuxの定期的なタスク

ワンタイムタスク

特定の時点では、一度実行した後にクリア

関連コマンド/プロセス

  • atコマンド
  • ATDプロセス

centos6では、システムサービスの名前:/etc/init.d/atd

ビューシステム起動時のプロセス:

[root@ecs-t6-large-2-linux-20190824103606 ~]# ps -ef | grep atd
root      4472     1  0 Sep04 ?        00:00:00 /usr/sbin/atd -f
root      9628  9222  0 18:21 pts/0    00:00:00 grep --color=auto atd

ワンタイムタスクの作成

フォーマット:

  • で[HH:MM]
  • で[HH:MM] [YYYY-MM-DD]
  • 今+数字で[分|時間| 日| 週]

例:スケジュールされたタスク、次の分を作成し、ファイルを作成します

[root@ecs-t6-large-2-linux-20190824103606 init.d]# at 18:33
at> touch 123
at> <EOT>
job 3 at Sat Sep 14 18:33:00 2019
[root@ecs-t6-large-2-linux-20190824103606 init.d]# ll
total 44
-rw-r--r--  1 root root     0 Sep 14 18:33 123

+ DスケジュールされたタスクのショートカットキーCTRLを保存

通常のタスクとしてファイル内のコマンド

フォーマット:時間-fファイルで

例:実行/root/test.sh後5分

at now + 5 minutes -f /root/test.sh

現在のシステム上の問合せ時間定期的なタスク

  • コマンド1:
at -l
[root@ecs-t6-large-2-linux-20190824103606 init.d]# at -l
没任何结果说明没有一次性任务
  • コマンド2:
atq
[root@ecs-t6-large-2-linux-20190824103606 init.d]# atq
没任何结果说明没有一次性任务

[root@ecs-t6-large-2-linux-20190824103606 init.d]# atq
5   Sat Sep 14 20:00:00 2019 a root
5  是任务号

タスクの数に応じて、指定された時間のタスクを削除するには

  • コマンド1
atrm [编号]
  • コマンド2
at -d

ワンタイムタスクの詳細を見ます

at -c [任务号]

タイムタスクファイル作成場所

/ var /スプール/ AT / *
このパスでは、すべてのファイルが存在し始めています

[root@ecs-t6-large-2-linux-20190824103606 init.d]# ll /var/spool/at/
total 8
-rwx------  1 root root 3085 Sep 14 18:37 a00005018ee170
drwx------. 2 root root 4096 Sep 14 18:33 spool

タスクが実行された後、ファイルが消えます

これは、ユーザがそれらのファイルにスケジュールされたタスクを使用できるかどうかを示します

  • /etc/at.deny:ユーザーのリストは、定期的なタスクを使用することはできません
  • /etc/at.allow:ユーザが利用できるこのリスト

定期的なタスク

計画反復作業の予約によると、

関連コマンド/プロセス

  • crontabのコマンド
  • crondプロセス

centos6では、タスクサービスに対応する期間は以下のとおりです。/etc/init.d/crond

プロセスが開始された場合は、システムを見ます

[root@ecs-t6-large-2-linux-20190824103606 ~]# ps -ef | grep crond
root      4474     1  0 Sep04 ?        00:00:00 /usr/sbin/crond -n
root      9699  9222  0 18:23 pts/0    00:00:00 grep --color=auto crond

サイクル作成したタスクのファイルの場所

/ var / spool / cron /ユーザ名

以下のように定期的なタスクの存在は、システムを表示することができます。

[root@ecs-t6-large-2-linux-20190824103606 init.d]# cat  /var/spool/cron/root 
5 11 * * * /tmp/touch_file

cronのサービス構成ファイル

[root@ecs-t6-large-2-linux-20190824103606 init.d]# cat /etc/crontab 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

我々はいくつかのコマンドラインをノックするときという意味以上のPATH、この5月のPATHおよびPATH異なるシステムは、これらのコマンドは、PATHシステムに応じて見つけることができるコマンドが、ことに注意してくださいデューティ・サイクルのPATHは、いくつかのパスが不足している場合、あなたリードサイクルは、コマンドを実行に失敗することがあります

  • PATHシステムを確認し、(私のデフォルトはまったく同じです)
[root@ecs-t6-large-2-linux-20190824103606 init.d]# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin

実際に行うにはどのようにコマンドが実行できない場合は?私は、コマンド/コマンドの前に絶対パス/ binを追加することができます

例:スクリプトファイルの作成

[root@ecs-t6-large-2-linux-20190824103606 tmp]# cat touch_file 
touch a$RANDOM

このスクリプトの実行

[root@ecs-t6-large-2-linux-20190824103606 tmp]# bash touch_file 
[root@ecs-t6-large-2-linux-20190824103606 tmp]# ll
total 48
-rw-r--r-- 1 root root     0 Sep 14 18:59 a21698

このスクリプトxに追加し、実行可能ファイルを許可

[root@ecs-t6-large-2-linux-20190824103606 tmp]# chmod +x touch_file 
[root@ecs-t6-large-2-linux-20190824103606 tmp]# ll
-rwxr-xr-x 1 root root    15 Sep 14 18:59 touch_file

再び実行します。

[root@ecs-t6-large-2-linux-20190824103606 tmp]# ./touch_file 
[root@ecs-t6-large-2-linux-20190824103606 tmp]# ll
total 48
-rw-r--r-- 1 root root     0 Sep 14 18:59 a21698
-rw-r--r-- 1 root root     0 Sep 14 19:01 a3460

我々は別のディレクトリに切り替えると、あなただけの絶対パスを追加してスクリプトを実行することができます

[root@ecs-t6-large-2-linux-20190824103606 tmp]# bash /tmp/touch_file 

サイクリックタスクに追加

ビューのcronサービスのログファイル

/ var / log / cronの

このログファイルからタスクの実行記録の歴史の中で見ることができます

cronのタスク管理計画

  • 編集スケジュールされたタスク:crontabの-e [-uユーザ名]
  • 表示スケジュールされたタスク:crontabの-l [-uユーザ名]
  • スケジュールされたタスクを削除するには、次のcrontab -r [-uユーザー名]

定期的なタスクのフォーマット

[root@ecs-t6-large-2-linux-20190824103606 init.d]# cat /etc/crontab 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed


*           *               *                   *                *
分钟      小时            日期                月份            星期
0-59      0-23             1-31              1-12            0-7

0  17  *  *  1- 5       周一到周五的每天17:00
30  8  *  *  1,3,5       星期1,3,5 每天八点半
0  8-18  *  *  *          每天的8-18点
0  12     *  *              每隔三天的12点

おすすめ

転載: www.cnblogs.com/ZhuChangwu/p/11519940.html