Python Script Deployment on Linux - Python Tutorial | Logic Practice
Python Course / Other / Python Script Deployment on Linux

Python Script Deployment on Linux

BLUF: This lesson on Python Script Deployment on Linux provides a comprehensive guide to understanding and implementing this concept in Python. Whether you're a beginner or looking to refresh your knowledge, you'll find clear explanations and interactive code examples here.
Key Concept: Python Script Deployment on Linux

Mastering Python Script Deployment on Linux is essential for building efficient Python applications. Focus on the syntax and the best practices highlighted in this tutorial.

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.

Example

$ 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.

Example

@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.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience