Using the Linux Crontab Command Like a Pro

August 5, 2023

Today’s the day I stop holding my breath and finally breathe…

After weeks of working on my Dorky Automation Emails, I’m finally done with the project. It doesn’t run in the cloud, as would be lovely, but it works using the Linux Crontab command.

Let me tell you a bit about the epiphany I had yesterday…

I could have continued trying to make my Python scripts function in the cloud, but right now, my focus is learning to program – not becoming a cloud expert. My biggest weakness is wanting to learn too much and do too much.

But having a purpose and knowing why I’m doing what I do makes me overcome this weakness.

That’s why I decided to put the cloud idea on hold and focus on more programming projects.

Before finishing, I decided to give the Linux Crontab command one more try.

But, of course, that didn’t go smoothly.

When I first wrote the Crontab command to automatically run my code, the command couldn’t locate the Python scripts I used I imported into my main script. No matter what I tried, Crontab wouldn’t work.

Then I met my night in shining armor.

After some research, I remembered the golden rule for running Python scripts…

Using virtual environments.

So I adapted.

Instead of calling my Python script directly with Crontab, I created a shell script that does the following:

  • Move to the directory with the Python script I want to run
  • Open a virtual environment in the terminal
  • Run the Python script

And finally, this method worked.

While I’m happy to see my project (basically) finished, there’s something about this that I’m more proud of. Learning to use Crontab has made me understand some of the inner workings of using Linux. In the programming world (and the Dorky World of Data), understanding Linux is crucial.

So while I didn’t become a master of the cloud yet, maybe this is gonna help me become a master of Linux. Maybe, right?