1

Hi I am new to programming and I have to write cronjob for my python file. My laptop is window so I just downloaded wsl and I wrote some lines for cronjob but it seems that non of them works.

*/2 * * * * /Document/카카오톡 받은 파일\crawling_html_css/try.py
*/2 * * * * python /Document/카카오톡 받은 파일\crawling_html_css/try.py
*/2 * * * * cd Desktop && /usr/bin/python3.8 try.py >> test.out

Where should I start to write path from?? Are those lines wrong?? Also I have no idea what is sh file because I saw this often when I search for what I should do. How do I check if my cronjobs are working?

Jola7373
  • 13
  • 4

1 Answers1

1

First check cron on wsl is running Crontab never executes in Windows Subsystem Linux

If it is, check the path is correct to the file you want to run. In wsl cd into the folder containing the file and run pwd to print the working directory, use that as the path.

A sh file is like a batch file for Linux systems, Google is your best friend for info, or duckduckgo of course. I would recommend you put the call to your python script in an sh file.

As an example i have a cron job set for 0 13 * * * /mnt/c/_stuff/backup.sh which calls the sh file backup.sh every day at one in the afternoon.

The internals of that file are not relevant to you but this is the sort of path you need to use. The file is set as executable chmod 777 backup.sh and you should be able to run it by typing ./mnt/c/_stuff/backup.sh from any directory. you would need to put the commands to run your python scripts in here.

Of course you can execute the single python script from cron itself without a sh file but i find a sh file gives you more options around tweaking and building up the job to run. For example something like */2 * * * * python /mnt/c/folder/folder/try.py

Damo
  • 5,698
  • 3
  • 37
  • 55