Answer the question
In order to leave comments, you need to log in
How to redirect all script output to a file?
Hello, I wrote a script, it should be executed periodically, I registered it in the cron, but there is a problem with output to a file
here crontab
* * * * * root python /home/root/main.py >> /home/root/app.log 2>&1
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def main():
pass
if __name__ == '__main__':
logger.info('Run script...')
main()
python /home/user/main.py >> /home/user/app.log 2>&1
Answer the question
In order to leave comments, you need to log in
registered it in the crown
In /etc/crontab? Only you need to specify the user in it, this field is not in user crontab.
Is that right 100%? What can be seen in /var/log/syslog?
there was also such a case in my practice
, by default, cron uses not bash but sh, because of which you can observe how the same thing works in bash and does not work in cron
, this is because bash is a thing actually user and what if cron was posix compatible it uses the standard shell interpreter
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question