Cant find cron log files

I have a container up and running on my raspberry PI 3. I have a couple of cron jobs setup but I cant find where the log file entries are going. Any suggestion where I can find them?

What file have you told the job to log to?

Sorry, I’m new to resin.io and new to Docker.

I didn’t specify where to log cron runs. My device is a raspberry Pi 3 running ResinOS. My Dockerfile.template is pasted below. I’ve looked in the standard places for raspberry PI and Linux systems but I cant seem to find them.

FROM resin/%%RESIN_MACHINE_NAME%%-node:6

# Install other apt deps
RUN apt-get update && apt-get install -y \
  xserver-xorg-core \
  xserver-xorg-input-all \
  xserver-xorg-video-fbdev \
  xorg \
  fluxbox \
  python-imaging-tk \
  unzip \
  cron && rm -rf /var/lib/apt/lists/*

# Set Xorg and FLUXBOX preferences
RUN mkdir ~/.fluxbox
RUN echo "xset s off" > ~/.fluxbox/startup && echo "xserver-command=X -s 0 dpms" >> ~/.fluxbox/startup

RUN echo "#!/bin/bash" > /etc/X11/xinit/xserverrc \
   && echo "" >> /etc/X11/xinit/xserverrc \
   && echo 'exec /usr/bin/X -s 0 dpms -nocursor -nolisten tcp "$@"' >> /etc/X11/xinit/xserverrc

# Defines our working directory in container
WORKDIR /usr/src/app

# Copies the package.json first for better cache on later pushes
COPY package.json package.json

# This install npm dependencies on the resin.io build server,
# making sure to clean up the artifacts it creates in order to reduce the image size.
RUN JOBS=MAX npm install --production --unsafe-perm && npm cache clean && rm -rf /tmp/*

# This will copy all files in our root to the working directory in the container
COPY . ./

# Install cronjobs to turn display on and off
RUN crontab jobs.txt

# Enable systemd init system in container
ENV INITSYSTEM on

# Start app
CMD ["bash", "/usr/src/app/start.sh"]

Okay, are you looking in the Host OS or inside the container? I presume this is a single container setup?

I looked in both places. The cron is running inside the container. Yes its a single container setup.

Hi @dreed47, I’ve checked it out, and by default, with the INITSYSTEM=on, the logs are in the normal systemd logs, not sent to a specific file. You can see them with journalctl -u cron (the cron service’s logs).

I see the jobs being triggered there just fine, such as:

...
Aug 15 14:11:01 253c3ec CRON[183]: pam_env(cron:session): Unable to open env file: /etc/default/locale: No such file or directory
Aug 15 14:11:01 253c3ec CRON[183]: pam_unix(cron:session): session opened for user root by (uid=0)
Aug 15 14:11:01 253c3ec CRON[184]: (root) CMD (echo "crontab job at $(date)")
Aug 15 14:11:01 253c3ec CRON[183]: (CRON) info (No MTA installed, discarding output)
Aug 15 14:11:01 253c3ec CRON[183]: pam_unix(cron:session): session closed for user root
...

If you want your jobs to have any output, you might have to either install postfix (hence the No MTA installed, discarding output message), or you can set your job up in a way that it saves to a file. See more info e.g. in this StackOverflow:

Does this help?

Yes, that helped very much! Thanks!

Great to hear!

Yeah, if using systemd, would recommend checking out journalctl and systemctl, for some handy tricks.

For example in this case, if you run with the -f flag to follow the logs of the specific unit, e.g. journalctl -f -u cron, then it will keep the flow open, and you’ll see whenever new logs come in. #tips

Also, besides crontab, if you use systemd already, could recommend checking out systemd timers, they are quite handy and versatile too, see for example https://wiki.archlinux.org/index.php/Systemd/Timers But if you are comfortable with cron, that should be fine too. :slight_smile: