LoginSignup
1
1

More than 3 years have passed since last update.

全ユーザのcron設定を一覧で出力する。

Last updated at Posted at 2020-09-13

概要

 cronは、Unix系サーバで動作するタスクスケジューラ用のデーモンプロセスです。
 cronの設定(タスクスケジュール)はユーザごとに設定可能である為、サーバ内の全設定を確認するには一手間かかったbashコマンドを発行します。

コマンド

# 1.管理者権限に移る
su -
# 2.ユーザごとのcron設定を出力する
for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done
# 3.管理者権限から抜ける
exit

解説

2のコマンドの各部は、次の処理内容になります。

cut -f1 -d: /etc/passwd
パスワードファイル「/etc/passwd」の各行で区切り文字「:」にて内容を分割し、その1項目目(ユーザ名)の値を抽出。

$(○○○)
コマンドを実行・展開。

for ××× in △△△; do □□□; done
△△△の各項目を×××に格納し、□□□の処理を実行。

echo $×××
×××の内容を出力。(このコマンド内ではユーザ名を出力)

crontab -u $××× -l
xxxのユーザのcron設定を出力。

参考

備考

本記事はブログ「雑用エンジニアの技術ノート」からの移行記事です。先のブログは削除予定です。

1
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
1
1