Other than their odd/awkward naming, cron jobs can be pretty useful.
From what I know, a cron job is just a job you can set in linux to run in the background off a timer. So you can set it to run on a specific month, day, time, or whatever, or you can set it to run every day, hour, minute, second, etc..
For me, I'm currently using a cron job to tell me (every hour) if there are any new listings on Craigslist sublets in Palo Alto.
Just a little background on the project, I'm running it on my Ubuntu AWS EC2 instance, using lxml/BeautifulSoup libraries for Python, and the Twilio API (and its Python wrapper) for this.
Setting up the Python file to scrape and send texts if it found anything new fortunately did not take too long - just one/two hours - but setting up the cron job was infuriating.
First I couldn't exactly get the timing syntax right, then I tried using a .sh file to make sure it would execute, then I had to make it executable, then I tried just calling a Python file, and it just kept going on and on and on.
But some of the things I learned along the way:
* */1 * * * is the same thing as * * * * * which tells the cron job to run every minute...
0 * * * * and @hourly actually get it to run hourly
- Make sure to make the file executable: chmod +x /path/to/file
- Also make sure to tell the terminal which intepreter to run: #!/path/to/interpreter
- Make sure to use the full path to the file you are executing.
- And ask smarter people for help more often
There is probably more I learned - but that is all I remember at 4:30 in the morning. The biggest fix that I cannot believe I messed up was just making sure to use the full path to the file you are executing to make sure the cron job can find it.
So here was my final cron job code:
0 * * * * /home/ubuntu/update_craigslist.py
And this was at the first line of my update_craigslist.py file:
Anyways - I plan on putting a lot more in depth (this was not in depth at all, I know) tutorials up as I continue to build and learn. In addition, there is a lot of stuff I've learned so far that I need to put up as well.