[Patch] Busybox-crond -> fallweise Unterdrückung von Log-Einträgen

PeterPawn

IPPF-Urgestein
Mitglied seit
10 Mai 2006
Beiträge
15,348
Punkte für Reaktionen
1,782
Punkte
113
Hi,

keine Ahnung, ob es sonst noch jemand brauchen kann ...

Mich hat es gestört, daß ein - mit hoher Frequenz - über crond gestarteter Job mir das syslog mit unnötigen Informationen bei jedem einzelnen Start dieses Jobs "zugemüllt" hat. Da andere Jobs aber durchaus protokolliert werden sollen und der Busybox-syslogd kein selektives Logging erlaubt, habe ich den Busybox-crond so gepatched, daß er das Verhalten des crond z.B. aus OpenSuSE (kein Logging, wenn der Job dem Nutzer 'root' gehört und die entsprechende Zeile in der crontab mit '-' beginnt) nachahmt.

Datei als "make/busybox/patches/900-busybox-crond.patch" speichern:
Code:
--- miscutils/crond.c.org       2014-01-09 19:15:44.000000000 +0100
+++ miscutils/crond.c   2014-01-13 21:42:44.167626618 +0200
@@ -69,6 +69,9 @@
        int cl_empty_mail_size;         /* size of mail header only, 0 if no mailfile */
        char *cl_mailto;                /* whom to mail results, may be NULL */
 #endif
+#if ENABLE_FEATURE_CROND_ROOT_NOLOG
+       smallint cl_nolog;              /* bool: disable logging of start message for job entries starting with a dash (-), only valid for user 'root' */
+#endif
        /* ordered by size, not in natural order. makes code smaller: */
        char cl_Dow[7];                 /* 0-6, beginning sunday */
        char cl_Mons[12];               /* 0-11 */
@@ -414,6 +417,13 @@
                        if (n < 6)
                                continue;
                        *pline = line = xzalloc(sizeof(*line));
+#if ENABLE_FEATURE_CROND_ROOT_NOLOG
+                       line->cl_nolog = 0;
+                       if (strcmp(fileName, "root") == 0 && *(tokens[0]) == '-') {
+                           line->cl_nolog = 1;
+                           (tokens[0])++;
+                       }
+#endif
                        /* parse date ranges */
                        ParseField(file->cf_username, line->cl_Mins, 60, 0, NULL, tokens[0]);
                        ParseField(file->cf_username, line->cl_Hrs, 24, 0, NULL, tokens[1]);
@@ -797,6 +807,9 @@

                        start_one_job(file->cf_username, line);
                        pid = line->cl_pid;
+#if ENABLE_FEATURE_CROND_ROOT_NOLOG
+                       if (!line->cl_nolog)
+#endif
                        crondlog(LVL8 "USER %s pid %3d cmd %s",
                                file->cf_username, (int)pid, line->cl_cmd);
                        if (pid < 0) {
--- miscutils/Config.src.org    2014-01-09 19:15:44.000000000 +0100
+++ miscutils/Config.src        2014-01-13 23:07:16.299410970 +0200
@@ -160,6 +160,14 @@
        help
          Command output will be sent to corresponding user via email.

+config FEATURE_CROND_ROOT_NOLOG
+       bool "Suppress logging of start information (root user only)"
+       default y
+       depends on CROND
+       help
+         A dash character (-) at the first position of the minute field
+          for an entry prevents crond from logging every start of that job.
+
 config FEATURE_CROND_DIR
        string "crond spool directory"
        default "/var/spool/cron"
und die Datei "make/busybox/busybox.rebuild-subopts.mk.in" mit folgendem Patch ändern:
Code:
Index: make/busybox/busybox.rebuild-subopts.mk.in
===================================================================
--- make/busybox/busybox.rebuild-subopts.mk.in  (Revision 12119)
+++ make/busybox/busybox.rebuild-subopts.mk.in  (Arbeitskopie)
@@ -168,6 +168,7 @@
 $(PKG)_REBUILD_SUBOPTS += FREETZ_BUSYBOX_FEATURE_CROND_CALL_SENDMAIL
 $(PKG)_REBUILD_SUBOPTS += FREETZ_BUSYBOX_FEATURE_CROND_D
 $(PKG)_REBUILD_SUBOPTS += FREETZ_BUSYBOX_FEATURE_CROND_DIR
+$(PKG)_REBUILD_SUBOPTS += FREETZ_BUSYBOX_FEATURE_CROND_ROOT_NOLOG
 $(PKG)_REBUILD_SUBOPTS += FREETZ_BUSYBOX_FEATURE_DATE_COMPAT
 $(PKG)_REBUILD_SUBOPTS += FREETZ_BUSYBOX_FEATURE_DATE_ISOFMT
 $(PKG)_REBUILD_SUBOPTS += FREETZ_BUSYBOX_FEATURE_DATE_NANO
Anschließend noch "make/busybox/generate.sh" aufrufen und dann sollte bei einem 'make menuconfig' für freetz unter
Code:
> Busybox applets > Miscellaneous Utilities > crond
die neue Option verfügbar sein.

Um dann für einen cron-Job die Protokollierung zu unterdrücken, muß die betreffende Zeile in der crontab - wie schon geschrieben - nur mit einem Bindestrich beginnen.
 

Zurzeit aktive Besucher

Statistik des Forums

Themen
246,741
Beiträge
2,256,724
Mitglieder
374,769
Neuestes Mitglied
Luckys123
Holen Sie sich 3CX - völlig kostenlos!
Verbinden Sie Ihr Team und Ihre Kunden Telefonie Livechat Videokonferenzen

Gehostet oder selbst-verwaltet. Für bis zu 10 Nutzer dauerhaft kostenlos. Keine Kreditkartendetails erforderlich. Ohne Risiko testen.

3CX
Für diese E-Mail-Adresse besteht bereits ein 3CX-Konto. Sie werden zum Kundenportal weitergeleitet, wo Sie sich anmelden oder Ihr Passwort zurücksetzen können, falls Sie dieses vergessen haben.