I have a python program which basically opens a file testlog.txt
, which should be in the same directory as the program file, and appends the current date and time stamp to it.
EDIT : The file open function is simply f = open(file,'a')
.
Let's say the program resides in /home/user1/pyscript/
the program will print the date/time as well as it's output. Now when I run the script from within that directory it runs fine.
Running it from /
directory gives me a permission error on writing the file. This is where my issue may be coming from but I want to understand the logic behind it.
I have a crontab entry for the script to run every minute. The entry looks like this:
*/1 * * * * sudo python /home/user1/pyscript/test.py >> /home/user1/pyscript/test.txt
When the job runs it actually writes the print output to the file test.txt
but it does not write to file testlog.txt
My question is if the cron job can write to one file how can it not have permission to write to the other file.
ls -l gives me following for the directory where the program file resides.:
drwxr-xr-x 6 ec2-user users 4096 Jul 27 20:29 pyscript