3 options
Bash cookbook : leverage bash scripting to automate daily tasks and improve productivity / Ron Brash, Ganesh Naik.
- Format:
- Book
- Author/Creator:
- Brash, Ron, author.
- Language:
- English
- Subjects (All):
- Linux.
- User interfaces (Computer systems).
- Physical Description:
- 1 online resource (260 pages) : illustrations
- Edition:
- 1st edition
- Place of Publication:
- Birmingham ; Mumbai : Packt, 2018.
- System Details:
- text file
- Summary:
- Create simple to advanced shell scripts and enhance your system functionality with effective recipes Key Features Automate tedious and repetitive tasks Create several novel applications ranging from a simple IRC logger to a Web Scraper Manage your system efficiently by becoming a seasoned Bash user Book Description In Linux, one of the most commonly used and most powerful tools is the Bash shell. With its collection of engaging recipes, Bash Cookbook takes you through a series of exercises designed to teach you how to effectively use the Bash shell in order to create and execute your own scripts. The book starts by introducing you to the basics of using the Bash shell, also teaching you the fundamentals of generating any input from a command. With the help of a number of exercises, you will get to grips with the automation of daily tasks for sysadmins and power users. Once you have a hands-on understanding of the subject, you will move on to exploring more advanced projects that can solve real-world problems comprehensively on a Linux system. In addition to this, you will discover projects such as creating an application with a menu, beginning scripts on startup, parsing and displaying human-readable information, and executing remote commands with authentication using self-generated Secure Shell (SSH) keys. By the end of this book, you will have gained significant experience of solving real-world problems, from automating routine tasks to managing your systems and creating your own scripts. What you will learn Understand the basics of Bash shell scripting on a Linux system Gain working knowledge of how redirections and pipes interact Retrieve and parse input or output of any command Automate tasks such as data collection and creating and applying a patch Create a script that acts like a program with different features Customize your Bash shell and discover neat tricks to extend your programs Compile and install shell and log commands on your system's console using Syslog Who this book is for The Bash Cookbook is for you if you are a power user or system administrator involved in writing Bash scripts in order to automate tasks. This book is also ideal if you are interested in learning how to automate complex daily tasks.
- Contents:
- Cover
- Title Page
- Copyright and Credits
- Packt Upsell
- Contributors
- Table of Contents
- Preface
- Chapter 1: Crash Course in Bash
- Getting started with Bash and CLI fundamentals
- Your first Bash script with Vim
- Creating and using basic variables
- Hands-on variable assignment
- Hidden Bash variables and reserved words
- Conditional logic using if, else, and elseif
- Evaluating binary numbers
- Evaluating strings
- Nested if statements
- Case/switch statements and loop constructs
- Basic case statement
- Basic loops
- For loop
- Do while loop
- Until loop
- Using functions and parameters
- Using a function with parameters within a for loop
- Including source files
- Including/importing a library script and using external functions
- Retrieving return codes and output
- Return code 101
- Linking commands, pipes, and input/output
- Redirection and pipe bonzanza
- Getting program input parameters
- Passing your program flags
- Getting additional information about commands
- Summary
- Chapter 2: Acting Like a Typewriter and File Explorer
- Introduction
- Basic searching for strings and files
- Getting ready
- How to do it...
- How it works...
- Using wildcards and regexes
- Math and calculations in script
- Striping/altering/sorting/deleting/searching strings with Bash only
- Using SED and AWK to remove/replace substrings
- Formatting your data/output using echo and printf
- Readying your script for different languages with internationalization
- How it works.
- Calculating statistics and reducing duplicates based on file contents
- Using file attributes with conditional logic
- Reading delimited data and altered output format
- Chapter 3: Understanding and Gaining File System Mastery
- Viewing files from various angles - head, tail, less, and more
- Searching for files by name and/or extension
- Creating a diff of two files and patching
- Creating symbolic links and using them effectively
- Crawling filesystem directories and printing a tree
- Finding and deleting duplicate files or directories
- Joining and splitting files at arbitrary positions
- Generating datasets and random files of various size
- Chapter 4: Making a Script Behave Like a Daemon
- Running a program continuously (forever) using looping constructs or recursion
- Keeping programs/scripts running after logoff
- Invoking commands when they require permissions
- Sanitizing user input and for repeatable results
- Making a simple multi-level user menu using select
- How to do it.
- How it works...
- Generating and trapping signals for cleanup
- Using temporary files and lock files in your program
- Leveraging timeout when waiting for command completion
- Creating a file-in-file-out program and running processes in parallel
- Executing your script on startup
- Chapter 5: Scripts for System Administration Tasks
- Gathering and aggregating system information
- Gathering network information and connectivity diagnostics
- Configuring basic network connectivity
- Monitoring directories and files
- Compressing and archiving files
- Rotating files from RAM to storage for log rotation
- Adding configuration to /etc/logrotate.d/
- Using Linux iptables for a firewall
- Accessing SQL databases remotely or locally
- Creating SSH keys for password less remote access
- Creating and configuring cron Jobs for task scheduling
- Creating users and groups systematically
- Chapter 6: Scripts for Power Users
- Creating Syslog entries and generating an alarm
- Getting ready.
- How to do it...
- Backing up and erasing media, disks, and partitions with DD
- Creating graphics and presentations on the CLI
- Checking for file integrity and tampering
- Mounting network file systems and retrieving files
- Browsing the web from the CLI
- Capturing network traffic headlessly
- Finding binary dependencies
- Fetching time from different locations
- Encrypting/decrypting files from a script
- Chapter 7: Writing Bash to Win and Profit
- Creating a lame utility HTTP server
- How to do it…
- How it works…
- Parsing RSS feeds and output HTML
- Scraping the web and collecting files
- Making a simple IRC chat bot logger
- Blocking IP addresses from failed SSH attempts
- Playing and managing audio from Bash
- Creating a simple NAT and DMZ firewall
- Parsing a GitHub project and generate a report
- Creating a poor man's incremental remote backup
- How it works….
- Using Bash scripts to monitor udev input
- Using Bash to monitor battery life and optimize it
- Using chroot and restricted Bash shells to secure scripts
- Chapter 8: Advanced Scripting Techniques
- Calculating and reducing the runtime of a script
- Writing one-line conditional statements and loops
- Avoiding command not found warnings/errors and improving portability
- Creating a config file and using it in tandem with your scripts
- Improving your shell - GCC and command line colors
- Adding aliases, and altering user paths/variables
- Echoing output to raw terminal devices
- Creating simple frontend GUIs for Bash scripts
- Compiling and installing your own Bash shell
- Recording terminal sessions for automation
- Writing high-quality scripts by example
- Other Books You May Enjoy
- Index.
- Notes:
- Includes index.
- Description based on print version record.
- ISBN:
- 9781788839174
- 178883917X
- OCLC:
- 1048789321
The Penn Libraries is committed to describing library materials using current, accurate, and responsible language. If you discover outdated or inaccurate language, please fill out this feedback form to report it and suggest alternative language.