Log cron process output to both stdout and log file?

55 Views Asked by At

I have a script running every minute on cron and want to output the script output to terminal as well as to a log file. I think I use tee -a for this.

Right now the python script just prints the current time.

* * * * * python script.py | tee -a script_times.log

The above logs to the file but not to stdout.

I thought tee outputs to stdout and to any given file.

How can I make it log out as well as log to file?

1

There are 1 best solutions below

1
Mikk Küttim On

If you're looking to write output to a specific terminal, you'd need to redirect it there, for example, * * * * * python script.py | tee -a script_times.log > /dev/pts/0. Replace /dev/pts/0 with your terminal's device file, typically found using the tty command