My first cron job

Posted on Leave a comment

That’s right. Believe it or not. I created my first cron job TODAY! This is what it looks like:

0 4 * * * cd /var/www/mysite/ && node gmailscripts/watch.js my-email-id@gmail.com

It’s a very simple job that calls a Node.js script to renew a watch I have on one of my Gmail accounts. at exactly 4:00am daily. Now, what is a watch or why I am watching my mailbox are beyond the scope of this little blog post. Basically, I have a nifty little Node.js API that I use as a webhook to get notification updates from Gmail whenever a new mail arrives. It then checks if the new mail has a specific subject and from address, which when true instructs the API to call a custom parser to scan the contents of the new mail and return me important bits of information that I then save in a database. Geeky? Perhaps it is. I plan to do a separate blog post on how you can do the same (not setting up cron, but watching Gmail mailboxes for new mail programmatically).

Back to cron again: it’s not that I didn’t know the concept of automated jobs before (in Linux or otherwise), I guess I never really needed to create a scheduled job before. Creating the job was not as much fun as reading the correct way to do it. I followed this Digital Ocean community tutorial, which is now 6 years old but stays relevant today.

On this topic, in my professional life I’ve literally seen people learning about this ‘cool’ tool and then misusing it for all sorts of software development things that can be (and should be) done using some form of publish-subscribe or message queue design pattern.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.