M
M
meeshanya2021-02-19 21:26:35
linux
meeshanya, 2021-02-19 21:26:35

How to write a file in python when run via cron?

A python3 program that has these lines:

python3
with open('log.txt', 'a') as f:
    f.write(date.strftime('%d-%m-%Y %X') +  ' some text')
    f.close()

Writes to the file what is required when I run it manually, but when it runs according to the cron schedule, nothing is written
. The log.txt file has the attributes -rw-rw-rw-

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pfg21, 2021-02-19
@meeshanya

study under which user the cron runs the command and in which directory (it is not yours by default ~)
for the future, learn to write full paths for all files and your hair will be soft and silky :)

D
Dr. Bacon, 2021-02-19
@bacon

Line 1, what is "python3" in the script
Line 2, do you understand what it means to use a relative path?
Line 3, well, almost no fault, except for such an addition of lines, well, so-so
line 4, why is this here?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question