-1

I wanted to execute my python file every 10 minutes. I am working with ubuntu instance. This statement is t working until the line of the file acess. I couldn't figure out the problem. I have tested this to /usr/bin/python to python3 and python3.6 as well

   */10 * * * * /usr/bin/python /home/ubuntu/Deploy/sam.py >> /home/ubuntu/test.log

The file acess doesn't work. How to give the file acess ?

sam.py

print('HI')
with open("EsText.txt", "a") as myfile:
    myfile.write("kugan")
    myfile.close()
Sathiyakugan
  • 674
  • 7
  • 20
  • Is this output file generated ? – Shivam Seth Sep 18 '18 at 12:59
  • 1
    Possible duplicate of [CronJob not running](/questions/22743548/cronjob-not-running) – tripleee Sep 18 '18 at 13:14
  • @ShivamSeth no! it's not executing ! – Sathiyakugan Sep 18 '18 at 13:15
  • Can u do 2 things 1st Manually run sam.py and check there is no issues, 2nd execute sam.py and add lon sleep and try to find if process is actually running if yes then instead of externally redirect o/p try logging inside code – Shivam Seth Sep 18 '18 at 13:36
  • Can you access `/var/log/syslog`? If so, try grepping it for "cron". Also, you're running from the `/home/ubuntu/Deploy` directory, but writing to `/home/ubuntu`. Do you have write permissions to that latter directory? – GreenMatt Sep 18 '18 at 15:39
  • @GreenMatt the print staement wroking . but there after that file write is not executing! – Sathiyakugan Sep 18 '18 at 15:46
  • @eaglerocks: So it seems your cron job can write to that directory, but there's a problem in your program. As Shivam said, run the program from the command line and figure out what's wrong with it. – GreenMatt Sep 18 '18 at 17:00

1 Answers1

1

your cron expression should be 0 0/10 * 1/1 * ? * You can take help from this

also try using > instead of >>

Rahul Raut
  • 1,099
  • 8
  • 15
  • This will do every ten minutes from where you start the cronjob. His format is correct if he wants it on every 10th minute – ltd9938 Sep 18 '18 at 13:13
  • It's not working. It's saying there's error. try this it's giving correct one https://crontab-generator.org/ @Rahul – Sathiyakugan Sep 18 '18 at 13:13