Greg,

20 avr. 2021, 19:22 de g...@wooledge.org:

> 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.
>
Agreed regarding `tee` working.

I was speaking about terminal so the OP can see your "final copy to stdout" but 
for me there is nowhere to display such output on the fly (that's the main 
value of `tee` to save to files while displaying the result on the screen, 
except if you see other advantages?).


>> 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.
>
Understood but why `tee` and not a simple redirection to a file (see below)?

>> 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
>
Absolutely not, you missed my redirection ;)

My suggestion was the following:
/my/job &>/var/tmp/my-job-output

Best regards,
l0f4r0

Reply via email to