I have a bash script that turns off stdout and stderr when not run interactively (i.e. run from CRON).
if [[ ! -t 0 && ! -t 1 ]]; then
#echo "The script is not called interactively. Close stdout and stderr."
# Close standard output file descriptor
exec 1<&-
# Close standard error file descriptor
exec 2<&-
INTERACTIVE=false
fi
echo " Interactive ? $INTERACTIVE" | tee -a "$WORK_DIR/log.txt"
As you can see from the last line, the bash script writes to a log file.
When the script is run interactively, I can see the output on the console AND in the log file.
When the script is run as a CRON job, I can see the output in the log file. So far, so good.
At some point in time, my bash script runs a deno program using the following command :
(deno run ./denopgm.ts | tee -a "$WORK_DIR/log.txt")&
wait
When the script is run interactively, I can see what deno writes on the console AND in the log file.
BUT when the script runs as a CRON job, its output is not written to the log file.
I wonder why...
cronjobs run in a different environment than your interactive jobs (PATH, current directory...) Are you sure that thisdenocommand is in thePATHthat yourcronjobs use? Try with its absolute path, maybe, to see if it is your issue. Note that./denopgm.tsshould probably also be adapted for acronjob, and possibly the value ofWORK_DIR(that you don't show).PATHvariable in yourcrontabfile.echoat the end won't work in the non-interactive environment, since it tries to write to the closed stdout. It's usually better to redirect stdout/stderr to/dev/nullto avoid errors.