How to peek at the output of a running crontab task on OpenBSD

cronopenbsd

I have an hourly hour-long crontab task running with some mtr (traceroute) output every 10 minutes (that is going to go for over an hour prior to it being emailed back to me), and I want to see the current progress thus far.

On Linux, it can be done by accessing the open fd of the temporary file to which the results of the script are saved.

How can I do this on OpenBSD?

I've tried doing fstat | fgrep -e USER -e cron -e mtr, but couldn't find any temporary files at all.

Best Answer

I’ve investigated the source as to how cron handles mailing the output from its jobs:

  • cron(8) sets up stdout and stderr of the running job and pipes it directly into mail(1), not leaving any temporary files. Look in do_command.c around line 411 (1).
  • mail(1) needs to fully ready its stdin, since it needs the headers. It opens a temporary file (usually /tmp/mail-R…), but removes it right away, as not to leave traces. Loøk in collect.c at line 83 (2).

In any case, there seems to be deliberate effort not to leave an interceptible temporary file lying around. If you need (or want) to intercept what’s going on in a long-running cronjob, you have to set up a temporary file yourself.

My suggestion at this point is to e.g. add tee $HOME/cronjob.out to your cronjob, which captures a copy of your job’s output in a safe place.

Related Question