Ask Ubuntu Asked on November 18, 2021
My crontab is not producing logs for a particular command I’m using to monitor my network; other commands work fine.
* * * * * /usr/bin/COMMAND opt1 opt2 >> /home/pi/LOG.log 2>&1
The log file is created, but the output of the command does not log. The command and logging works fine when run in it in the terminal. I’ve tried copying the cron environment and running the command manually:
With crontab -e
, I added:
* * * * * env > ~/cronenv
Then I run:
env - `cat ~/cronenv` /bin/sh
/usr/bin/COMMAND opt1 opt2
The COMMAND outputs as expected, but as soon as I try to log the output, I get empty logs:
/usr/bin/COMMAND opt1 opt2 > /home/pi/LOG.log 2>&1
/usr/bin/COMMAND opt1 opt2 | tee /home/pi/LOG.log 2>&1
Switching my shell in crontab -e
to SHELL=/bin/bash
also has no effect.
Not sure if it’s relevant, but the command I’m struggling with takes several seconds to run, outputs in color with somewhat fancy formatting, unicode characters, etc. when I run it in the terminal, but it still logs fine. When I run it from the cronenv
I created, it does not display in color, but displays in much the same way it does when I save it to a log from terminal.
EDIT:
This is working in the ~/cronenv
environment I made, but the log is created but empty when run through cron (as before):
/usr/bin/unbuffer /usr/bin/COMMAND opt1 opt2 > /home/pi/LOG.log 2>&1
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP