Chapter 18: Utilize Macbook Crontab to Automate Running Amazon Competitor Price Tracker and Updating P&L Calculator and Product Market Value
Can Python really help you save a huge amount of time? The answer depends because it is not when you manually command B the script every time. It’s so manual-driven to update the pricing data using this method. This is not the purpose of the Python application. The destination picture should be someone else on behalf of you. The bot, she or he executes the Python script automatically in the background of your local device or on the cloud server.
Cron system and crontab is the one in the background in your local Macbook. Every time you open the P&L calculator on Google Sheets, the Amazon competitor product pricing data is up-to-date. So you can instantly understand if your product pricing is competitive or not in the search result or somewhere else.
In this chapter, I would walk you through how to use Crontab to automate Python scripts. By the end of this Python Tutorial, you can learn what Crontab is. And you can pick up what commands you can use. Of course, you can master how to install and create the automatic execution with the help of this bot. It would help you learn my next Python Tutorial regarding server deployment as well.
Table of Contents: Set up Task Schedulers Using Macbook Crontab
- What’s Crontab and How it works with your Python Scripts
- Use Crontab Guru Schedule Stimulator
- Grant Cron and Terminal Full Disk Access in Macbook
- Create a Crontab Schedule in Macbook Using
Crontab -e
- Check the Crontab Status Using
Crontab -l
,Mail
and Delete the existing Crontab demands usingCrontab -r
- FAQ
What’s Crontab and How It Works with your Python Scripts
Cron is a computer daemon. You can use it to execute scheduled and desired tasks in your computer background. It can be a one-off assignment or a recurring task.
A crontab file is just a simple text file. It contains a list of commands, and these commands aim to activate and run at specified times. It has a set of crontab commands, and the cron daemon checks the commands in the crontab file and executes them in the system background.
In Macbook, you can open the terminal and enter the command crontab -e
. You can add the crontab commands to automate your Python scripts stored in your Macbook. It means as long as your laptop is open and connected to the internet, the Python scripts can work automatically in the background without any manuals.
For example, previously I shared how to create an Amazon price tracker. Basically, this tracker needs to update at a designated time slot, otherwise, you can’t see the up-to-date market value. However, it’s not real to update manually by yourself. So, crontab can be your personal assistant.
Crontab Guru Schedule Stimulator
First thing first, we need to learn how to set the timer by using Crontab. After all, this is the primary feature of Crontab. There is a stimulator Crontab Guru, and you can search in Google and go to have a look at the simulator
By default, there are 5 variables of the timer setting. They are the minute, hour, day of the month, month, and day of the week. Apart from the number you can use, there are some signals you can use as well. They represent some commands. For example, *
represents any value. As you can see in the screenshot below, there is just the number 5 in the minute variable, and the rest of the variables are *
. That means we need to run the Python scripts every 5 mins.
For more details, please check out the simulator and try to play around.
Grant Cron and Terminal Full Disk Access in Macbook
You might be aware, Crontab seems to not work on Macbook after you tried to run the Python scripts in the terminal. In fact, it’s dealing with the permission issue, because since MacCatalina, we need to do further steps to grant Cron permission access. Below are the steps
- Open preferences and go to
“Security & Privacy” -> “Privacy”
- Scroll down to
“Full Disk Access”
on the left side and select it. - Hit the unlock icon and enter your password
- Hit the
“+”
sign to add an application - Type
“command+shift+G”
to bring up the got to file dialog box - Enter the full pathname to the application, that is
/usr/sbin/cron and click on “Go”
- Click
“Open”
It should show up in the list with a checkmark next to it. I tried it with a simple csh script in cron and it worked.
What’s more, we also need to grant Terminal to Full disk as well, and the steps would be similar to the Cron steps.
Create a Crontab Schedule in Macbook Using Crontab -e
Now you might master how to set the timer, you can use the timer setting on the Crontab commands in Macbook Terminal. Basically, the crontab creation formula is the timer plus the application plus the Python Script
* * * * * + Path of Python3 application + Python script
First thing first, you need to copy your existing Python3 application location path. Crontab can’t detect your current shell applications automatically. You need to tell it which one you are going to use and open the scripts.
You can enter “which python3”
or "which python"
in the terminal and copy this path in advance. You would use this path later on.
Secondly, please go to your Python script folder and copy the file location and file name. You would also use it after the Python application path. It can tell Python which script you are going to run.
Last but not least, you can enter crontab -e
and go into the editor environment. Press "I"
to start the editor mode. Then, you can fill in the timer setting, python application path, and the script location and name. Please keep in mind that crontab doesn’t allow any space to exist in the application path and file path. Being said that, each section needs a space to separate.
Then you can press “ESC”
, and type in “:wq”
to exit the editor mode. Here has a stable of commands you can use in the vi editor.
Check the Crontab Status Using Crontab - l
, mail
and Delete the Crontab Demands Using Crontab -r
Entering crontab -l
in the terminal can show you the crontab automation commands you set up just now.
In some cases, you might come across you can’t create the commands by popping up this message in the terminal “/usr/bin/vi exited with status 1”
. The reason for this is because your system hasn’t installed the vi editor yet.
The solution is just to type in “export EDITOR=vim”
in the terminal, and then fill in crontab -e
to restart the editing
What’s more, in the terminal interface after coming out from the crontab editor, Crontab will not update you if the automation is working or not. On the other hand, you need to check the messages from the Cron system.
It’s very simple by just typing in “mail”
in the terminal, and you can get back a list of emails. Entering the number of the mail, you can open the message and understand the automation result. If your commands have any problems, you can learn from the message.
I hope you enjoy reading Chapter 18: Utilize Macbook Crontab to Automate Running Amazon Competitor Price Tracker and Updating P&L Calculator and Product Market Value. If you did, please support us by doing one of the things listed below, because it always helps out our channel.
- Support and donate to our channel through PayPal (paypal.me/Easy2digital)
- Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
- Follow and like my page Easy2Digital Facebook page
- Share the article to your social network with the hashtag #easy2digital
- Buy products with Easy2Digital 10% OFF Discount code (Easy2DigitalNewBuyers2021)
- You sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount codes
- Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (www.patreon.com/louisludigital)
FAQ:
Q1: What are the specifications of the Macbook Crontab?
A: The Macbook Crontab comes with a 13-inch Retina display, 8GB RAM, 256GB SSD, and an Intel Core i5 processor.
Q2: What operating system does the Macbook Crontab use?
A: The Macbook Crontab runs on macOS.
Q3: Does the Macbook Crontab have a backlit keyboard?
A: Yes, the Macbook Crontab features a backlit keyboard for convenient typing in low-light conditions.
Q4: How long is the battery life of the Macbook Crontab?
A: The Macbook Crontab has a battery life of up to 10 hours, allowing you to use it throughout the day without needing to recharge.
Q5: Does the Macbook Crontab support Touch ID?
A: Yes, the Macbook Crontab is equipped with Touch ID for secure fingerprint authentication and Apple Pay.
Q6: What ports are available on the Macbook Crontab?
A: The Macbook Crontab includes two Thunderbolt 3 (USB-C) ports, a headphone jack, and an SDXC card slot.
Q7: Can I connect external displays to the Macbook Crontab?
A: Yes, the Macbook Crontab supports up to two external displays with up to 6K resolution.
Q8: Is the Macbook Crontab lightweight and portable?
A: Yes, the Macbook Crontab weighs just 2.8 pounds and is only 0.63 inches thin, making it highly portable.
Q9: Does the Macbook Crontab have a built-in webcam?
A: Yes, the Macbook Crontab comes with a 720p FaceTime HD camera for video calls and conferences.
Q10: What is the warranty on the Macbook Crontab?
A: The Macbook Crontab comes with a one-year limited warranty, which covers hardware defects and repairs.