質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.41%
cron

cronは、Unix系OS上でデーモンプロセスとして動作する、スクリプトの自動実行が可能なジョブスケジューラです。

Q&A

解決済

2回答

610閲覧

Logroteがcronで動かない

ryoma7i

総合スコア5

cron

cronは、Unix系OS上でデーモンプロセスとして動作する、スクリプトの自動実行が可能なジョブスケジューラです。

0グッド

0クリップ

投稿2023/03/14 05:37

logroteで設定しcronで動かすように設定してるのですが・・。
(logorote.confとcorntabには 0 0 * * * root run-parts /etc/cron.daily)

昨日設定して今朝確認したところ動いておりませんでした。
手動実行(sudo logrotate -f /etc/logrotate.conf)しましたが、それは普通に動いてました。

調べてみるとlogorote.timerなるものがあるようですが該当のフォルダには
無かったです。
パッケージなどはyumで調べてみましたが当たりがつきません。。
どうすればcronで動くようになりますでしょうか。
デフォルトのままであればlogorote.confで週次の4週分バックアップとしては動作は
していたのですが何が悪かったのかわかりません。

どうぞよろしくお願い致します。

[root@hogehoge timers.target.wants]# ls -l
total 3
lrwxrwxrwx. 1 root root 43 May 5 2021 dnf-makecache.timer
lrwxrwxrwx. 1 root root 44 May 5 2021 nm-cloud-setup.timer
lrwxrwxrwx. 1 root root 44 May 5 2021 unbound-anchor.timer

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

otn

2023/03/14 08:20 編集

> logroteで設定しcronで動かすように設定してるのですが・・。 > (logorote.confとcorntabには 0 0 * * * root run-parts /etc/cron.daily) cronからlogrotateを動かす設定にしている部分を質問文に追記しましょう。どのファイルに何と書いてあるか。
ryoma7i

2023/03/14 08:19

2行目に記載しておりますが・・・。
otn

2023/03/14 08:21 編集

それは、cronから/etc/cron.dally/*を起動するという記述です。
ryoma7i

2023/03/14 08:23

配下のlogoroteがありますが、そこはデフォルトのままです。
otn

2023/03/14 08:29

/etc/cron.daily/logrotate が存在して、中に、/usr/sbin/logrotate /etc/logrotate.conf の記述があると言うことですか?
otn

2023/03/14 08:51 編集

logについての記述が無いのですが、見てないのであれば、cronのlogを見てみましょう。
ryoma7i

2023/03/15 01:17

ご連絡ありがとうございます。 logrotateの記述はデフォルトのままで指摘の/usr/sbin/logrotate /etc/logrotate.confはあります。 ################################### [root@hoge cron.daily]# cat logrotate #!/bin/sh /usr/sbin/logrotate /etc/logrotate.conf EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit $EXITVALUE ################################### cronのログですは指定してる時間からのログは以下でした Mar 15 00:00:02 OaSovi_mark2 CROND[12716]: (root) CMD (root run-parts /etc/cron.daily) Mar 15 00:00:02 OaSovi_mark2 CROND[12703]: (root) CMDOUT (/bin/sh: root: command not found) Mar 15 00:01:01 OaSovi_mark2 CROND[12728]: (root) CMD (run-parts /etc/cron.hourly) Mar 15 00:01:01 OaSovi_mark2 run-parts[12728]: (/etc/cron.hourly) starting 0anacron Mar 15 00:01:01 OaSovi_mark2 anacron[12737]: Anacron started on 2023-03-15 Mar 15 00:01:01 OaSovi_mark2 anacron[12737]: Normal exit (0 jobs run) Mar 15 00:01:01 OaSovi_mark2 run-parts[12728]: (/etc/cron.hourly) finished 0anacron Mar 15 01:01:01 OaSovi_mark2 CROND[12853]: (root) CMD (run-parts /etc/cron.hourly) Mar 15 01:01:01 OaSovi_mark2 run-parts[12853]: (/etc/cron.hourly) starting 0anacron Mar 15 01:01:01 OaSovi_mark2 anacron[12862]: Anacron started on 2023-03-15 Mar 15 01:01:01 OaSovi_mark2 anacron[12862]: Normal exit (0 jobs run) Mar 15 01:01:01 OaSovi_mark2 run-parts[12853]: (/etc/cron.hourly) finished 0anacron どうぞよろしくお願い致します。
ryoma7i

2023/03/15 01:26

追加です。 anacrontabについてはコメントアウトして稼働させないようにしてました。 [root@hoge log]# cat /etc/anacrontab # /etc/anacrontab: configuration file for anacron # See anacron(8) and anacrontab(5) for details. SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # the maximal random delay added to the base delay of the jobs RANDOM_DELAY=45 # the jobs will be started during the following hours only START_HOURS_RANGE=3-22 #period in days delay in minutes job-identifier command #1 5 cron.daily nice run-parts /etc/cron.daily #7 25 cron.weekly nice run-parts /etc/cron.weekly #@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
guest

回答2

0

ログに、

(root) CMDOUT (/bin/sh: root: command not found)

というエラーが出ていますね。

corntabには 0 0 * * * root run-parts /etc/cron.daily

は、/etc/crontabに書くときの書き方です。そのままrootでのcrontab -eの編集(あるいはcrontab ファイル名のファイル内)で書いてしまったのでしょう。

logorote.confとcorntabには 

とお書きなのでてっきり、/etc/logrotate.conf/etc/crontabに書いた物と思ってました。

/etc/crontabには、どのユーザー権限で実行するかを書く必要があるのですが、
crontab -e(ファイルとしては、/var/spool/cron/ユーザ名)の場合はどのユーザー権限で実行するか決まっているのでこの欄はありません。

/etc/crontab0 0 * * * root run-parts /etc/cron.dailyと書くのと、
rootユーザー権限でcrontab -e等で0 0 * * * run-parts /etc/cron.dailyと書くのは、効果としては同じです。

投稿2023/03/15 02:51

otn

総合スコア85110

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

自己解決

あー確かに
ありがとうございます。
すぐ修正します。

投稿2023/03/15 03:53

ryoma7i

総合スコア5

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.41%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問