Bug#887035: cron: Logging to STDOUT when in foreground mode

2022-12-13 Thread Nick Reilingh
On Thu, 28 Jan 2021 17:38:00 + prog+debian-bug-887...@posteo.org wrote:
> For the use case of containerized environments BusyBox already provides
> a cron applet with custom logging capabilities:
> 
> busybox crond -f -L /dev/stdout

I am working in a debian-based container and the busybox available via apt-get 
appears not to have crond available.

Dockerfile:
FROM debian

RUN apt-get update && apt-get install -y busybox

CMD ["bash"]

$ docker build -t test .
$ docker run --rm -it test
# busybox crond -f
crond: applet not found

Can you clarify how one can use busybox’s crond in a containerized environment?

Thank you,
Nick R.


Bug#887035: cron: Logging to STDOUT when in foreground mode

2021-01-28 Thread prog+debian-bug-887035
For the use case of containerized environments BusyBox already provides
a cron applet with custom logging capabilities:

busybox crond -f -L /dev/stdout



Bug#887035: cron: Logging to STDOUT when in foreground mode

2018-01-12 Thread Greek

Package: cron
Version: 3.0pl1-127+deb8u1
Severity: wishlist
Tags: patch


Dear Maintainer,

it makes sense to me to Log output to stdout, when cron is executed in 
foreground mode using the -f argument.
This can be especially helpful in containerized environments (LXC, 
Docker), where a syslog facility is most of the times not available, and 
the logging can be handled with a simple redirect.


I have included a patch, which implements this functionality.
NOTE: This patch also incorporates the fix for Bug#887014!

If you need any more info/help, please do not hesitate to contact me (or 
reply to this bug report).


-- Package-specific info:
--- EDITOR:


--- /usr/bin/editor:
/bin/nano

--- /usr/bin/crontab:
-rwxr-sr-x 1 root crontab 36008 Jun 11  2015 /usr/bin/crontab

--- /var/spool/cron:
drwxr-xr-x 3 root root 4 Jan 12 13:58 /var/spool/cron

--- /var/spool/cron/crontabs:
drwx-wx--T 2 root crontab 2 Jun 11  2015 /var/spool/cron/crontabs

--- /etc/cron.d:
drwxr-xr-x 2 root root 4 Jan 12 13:58 /etc/cron.d

--- /etc/cron.daily:
drwxr-xr-x 2 root root 11 Jan 12 13:58 /etc/cron.daily

--- /etc/cron.hourly:
drwxr-xr-x 2 root root 3 Jan 12 13:58 /etc/cron.hourly

--- /etc/cron.monthly:
drwxr-xr-x 2 root root 4 Jan 12 13:58 /etc/cron.monthly

--- /etc/cron.weekly:
drwxr-xr-x 2 root root 5 Jan 12 13:58 /etc/cron.weekly


-- System Information:
Debian Release: 8.10
  APT prefers oldstable-updates
  APT policy: (500, 'oldstable-updates'), (500, 'oldstable')
Architecture: amd64 (x86_64)

Kernel: Linux 4.9.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash
Init: unable to detect

Versions of packages cron depends on:
ii  adduser  3.113+nmu3
ii  debianutils  4.4+b1
ii  dpkg 1.17.27
ii  init-system-helpers  1.22
ii  libc6    2.19-18+deb8u10
ii  libpam-runtime   1.1.8-3.1+deb8u2
ii  libpam0g 1.1.8-3.1+deb8u2+b1
ii  libselinux1  2.3-2
ii  lsb-base 4.1+Debian13+nmu1

Versions of packages cron recommends:
ii  exim4  4.84.2-2+deb8u4
ii  exim4-daemon-light [mail-transport-agent]  4.84.2-2+deb8u4

Versions of packages cron suggests:
ii  anacron    2.3-23
pn  checksecurity  
ii  logrotate  3.8.7-1+b1

Versions of packages cron is related to:
pn  libnss-ldap   
pn  libnss-ldapd  
pn  libpam-ldap   
pn  libpam-mount  
pn  nis   
pn  nscd  

-- Configuration Files:
/etc/crontab changed:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 *    * * *    root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *    root    test -x /usr/sbin/anacron || ( cd / && 
run-parts --report /etc/cron.daily )
47 6    * * 7    root    test -x /usr/sbin/anacron || ( cd / && 
run-parts --report /etc/cron.weekly )
52 6    1 * *    root    test -x /usr/sbin/anacron || ( cd / && 
run-parts --report /etc/cron.monthly )

* * * * * root echo test >> /var/log/test


-- no debconf information

diff -u cron-3.0pl1/cron.c cron-3.0pl1/cron.c
--- cron-3.0pl1/cron.c
+++ cron-3.0pl1/cron.c
@@ -106,7 +106,7 @@
setlocale(LC_COLLATE, "C"); /* Except for collation, since 
load_database() uses a-z */
/* Except that "US-ASCII" is preferred to "ANSI_x3.4-1968" in MIME,
 * even though "ANSI_x3.4-1968" is the official charset name. */
-   if ( ( cs = nl_langinfo( CODESET ) ) != 0L && 
+   if ( ( cs = nl_langinfo( CODESET ) ) != 0L &&
strcasecmp(cs, "ANSI_x3.4-1968") != 0 )
strncpy( cron_default_mail_charset, cs, MAX_ENVSTR );
else
@@ -123,12 +123,12 @@
} else if (!stay_foreground) {
switch (fork()) {
case -1:
-   log_it("CRON",getpid(),"DEATH","can't fork");
+   log_it(LOG_ERR, "CRON", getpid(), "DEATH", "can't 
fork");
exit(0);
break;
case 0:
/* child process */
-   log_it("CRON",getpid(),"STARTUP","fork ok");
+   log_it(LOG_INFO, "CRON", getpid(), "STARTUP", "fork 
ok");
(void) setsid();
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
@@ -234,8 +234,8 @@
getpid(), timeRunning - virtualTime))
/* run wildcard jobs for current minute */
find_jobs(timeRunning, , TRUE, FALSE);
-   
-   /* run fixed-time jobs for each minute missed 
*/ 
+
+   /* run fixed-time jobs for each minute missed */
do {
if (job_runqueue())
sleep(10);
@@ -245,7 +245,7 @@
} while