Mastering Python Scripting for System Administrators
eBook - ePub

Mastering Python Scripting for System Administrators

Write scripts and automate them for real-world administration tasks using Python

Ganesh Naik

Share book
  1. 318 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering Python Scripting for System Administrators

Write scripts and automate them for real-world administration tasks using Python

Ganesh Naik

Book details
Book preview
Table of contents
Citations

About This Book

Leverage the features and libraries of Python to administrate your environment efficiently.

Key Features

  • Learn how to solve problems of system administrators and automate routine activities
  • Learn to handle regular expressions, network administration
  • Building GUI, web-scraping and database administration including data analytics

Book Description

Python has evolved over time and extended its features in relation to every possible IT operation. Python is simple to learn, yet has powerful libraries that can be used to build powerful Python scripts for solving real-world problems and automating administrators' routine activities. The objective of this book is to walk through a series of projects that will teach readers Python scripting with each project.

This book will initially cover Python installation and quickly revise basic to advanced programming fundamentals. The book will then focus on the development process as a whole, from setup to planning to building different tools. It will include IT administrators' routine activities (text processing, regular expressions, file archiving, and encryption), network administration (socket programming, email handling, the remote controlling of devices using telnet/ssh, and protocols such as SNMP/DHCP), building graphical user interface, working with websites (Apache log file processing, SOAP and REST APIs communication, and web scraping), and database administration (MySQL and similar database data administration, data analytics, and reporting).

By the end of this book, you will be able to use the latest features of Python and be able to build powerful tools that will solve challenging, real-world tasks

What you will learn

  • Understand how to install Python and debug Python scripts
  • Understand and write scripts for automating testing and routine administrative activities
  • Understand how to write scripts for text processing, encryption, decryption, and archiving
  • Handle files, such as pdf, excel, csv, and txt files, and generate reports
  • Write scripts for remote network administration, including handling emails
  • Build interactive tools using a graphical user interface
  • Handle Apache log files, SOAP and REST APIs communication
  • Automate database administration and perform statistical analysis

Who this book is for

This book would be ideal for users with some basic understanding of Python programming and who are interested in scaling their programming skills to command line scripting and system administration.

Prior knowledge of Python would be necessary.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Mastering Python Scripting for System Administrators an online PDF/ePUB?
Yes, you can access Mastering Python Scripting for System Administrators by Ganesh Naik in PDF and/or ePUB format, as well as other popular books in Computer Science & System Administration. We have over one million books available in our catalogue for you to explore.

Information

Year
2019
ISBN
9781789134261
Edition
1

Python Scripting Overview

Python is a scripting language, created by Guido van Rossum in 1991, which is used in various applications, such as game development, GIS programming, software development, web development, data analytics, machine learning, and system scripting.
Python is an object-oriented, high-level programming language with dynamic semantics. Mainly, Python is an interpreted language. Python is used for rapid application development, as it has all of the advanced features for development.
Python is simple and easy to learn, as its syntax makes programs more readable. Hence, the program maintenance cost is low.
Python has one more important feature of importing modules and packages. This feature allows for code reuse. The Python interpreter is easy to understand. We can write the complete code one by one in it and, as Python is an interpreted language, the code gets executed line by line. Python also has a wide range of libraries for advanced functionality.
This chapter will cover the following topics:
  • Python scripting
  • Installing and using Python and various tools
  • Variables, numbers, and strings
  • Python supported data structures and how to use all of these concepts in a script
  • Decision making; that is, the if statement
  • Looping statements; that is, the for and while loops
  • Functions
  • Modules

Technical requirements

Before you start reading this book, you should know the basics of Python programming, such as the basic syntax, variable types, tuple data type, list dictionary, functions, strings, and methods. Two versions, 3.7.2 and 2.7.15, are available at python.org/downloads/. In this book we'll work with version 3.7 for code examples and package installing.
Examples and source code for this chapter are available in the GitHub repository: https://github.com/PacktPublishing/Mastering-Python-Scripting-for-System-Administrators-.

Why Python?

Python has a wide range of libraries for open source data analysis tools, web frameworks, testing, and so on. Python is a programming language that can be used on different platforms (Windows, Mac, Linux, and embedded Linux H/W platforms, such as Raspberry Pi). It's used to develop desktop as well as web applications.
Developers can write programs with fewer lines if they use Python. Prototyping is very quick, as Python runs on an interpreter system. Python can be treated in an object-oriented, a procedural, or a functional way.
Python can do various tasks, such as creating web applications. It is used with the software to create workflows; it connects to database systems, handles files, handles big data, and performs complex mathematics.

Python syntax compared to other programming languages

The code written in Python is highly readable because it's similar to the English language. To complete a command, Python uses new lines.
Python has a great feature: indentation. Using indentations, we can define the scope for decision-making statements, loops such as for and while loops, functions, and classes.

Python installation

In this section, we will be learning about the installation of Python on different platforms, such as Linux and Windows.

Installation on the Linux platform

Most Linux distributions have Python 2 in their default installations. Some of them also have Python 3 included.
To install python3 on Debian-based Linux, run the following command in the Terminal:
sudo apt install python3
To install python3 on centos, run the following command in the Terminal:
sudo yum install python3
If you are unable to install Python using the preceding commands, download Python from https://www.python.org/downloads/ and follow the instructions.

Installation on the Windows platform

For installing Python in Microsoft Windows, you'll have to download the executable from python.org and install it. Download python.exe from https://www.python.org/downloa...

Table of contents