On Tue, Apr 20, 2021 at 07:14:50PM +0200, l0f...@tuta.io wrote:
> > a b c d e   /my/job 2>&1 | tee /var/tmp/my-job-output
> >
> Greg, I don't understand the usage of `tee` here as there is no associated 
> terminal session (cron is not interactive).

tee(1) simply reads once and writes many times.  Specifically, it writes
a copy of its input to each of the files you give it as arguments, and
then one final copy to stdout (standard output).

It has nothing to do with terminals.

> I mean, where can the OP expect the output to be automatically displayed 
> please (I'm not speaking about the file of course)?

The output (both stdout and stderr) of the program spawned by cron(8)
is normally captured and then sent in an email to the job owner.

The OP is receiving the email just fine, but wants to be able to "watch"
the job in progress before the email arrives.  So, we simply need the
job to make a second copy of its output somewhere the OP can find it.
Thus, tee.

The OP can then run "tail -f /var/tmp/my-job-output" in their terminal
at any point after the job starts, to watch the fun.

> I'm asking because you suggest  `2>&1 | tee /var/tmp/my-job-output` and not 
> `&> /var/tmp/my-job-output`...

Your syntax makes no sense.  You proposed this?

/my/job & /var/tmp/my-job-output

That would run /my/job as a background process (even though by any
sensible definition, a cron job is already as "backgrounded" as you
could want), and then tries to run /var/tmp/my-job-output as a second
command.  I can only imagine that will fail, either because that file
doesn't exist at all, or because it's not executable, or because it
doesn't contain a valid program.

Reply via email to