Therefore, we have successfully completed the Python script (blocker.py), which is functioning correctly. Now, it is time to configure this script to execute automatically at system startup.
The method for setting up a script to execute at system startup varies based on the operating system being used. In this segment of the tutorial, we will outline the procedures applicable to both Linux and Windows environments.
Procedure
To set up a script to execute during the system startup on a Linux operating system, it is essential to modify the appropriate entry within the crontab schedule.
The crontab can be described as a collection that holds the commands intended to be executed on a consistent timetable. The term crontab is derived from "cron table," which refers to a predetermined schedule that dictates the execution of scripts at regular intervals.
Steps for Script deployment on Linux
Follow the following steps.
Step 1:
Access the crontab by utilizing the -e option. Execute the subsequent command in the terminal on a Linux system.
$ sudo crontab -e
This action will launch a crontab file that appears as follows.
Step 2:
Next, insert the subsequent line into the file and ensure to save it.
@reboot python3 /home/logicpractice/Desktop/Python/website_blocker/blocker.py
Step 3:
Please initiate a system restart immediately. Upon rebooting, our script named blocker.py is configured to execute during the system's start-up sequence. Currently, we are within the designated working hours. Therefore, let us attempt to access Facebook via the web browser.
As illustrated in the image above, the website www.facebook.com is unable to establish a connection. Therefore, our script is functioning correctly upon system startup since the website is not connecting.