Linux Shell Scripting Cookbook, Second Edition

Linux Shell Scripting Cookbook, Second Edition

Shantanu Tushar, Sarath Lakshman

Language: English

Pages: 384

ISBN: 1782162747

Format: PDF / Kindle (mobi) / ePub


Don't neglect the shell - this book will empower you to use simple commands to perform complex tasks. Whether you're a casual or advanced Linux user, the cookbook approach makes it all so brilliantly accessible and, above all, useful.

Overview

  • Master the art of crafting one-liner command sequence to perform text processing, digging data from files, backups to sysadmin tools, and a lot more
  • And if powerful text processing isn't enough, see how to make your scripts interact with the web-services like Twitter, Gmail
  • Explores the possibilities with the shell in a simple and elegant way - you will see how to effectively solve problems in your day to day life

In Detail

The shell remains one of the most powerful tools on a computer system — yet a large number of users are unaware of how much one can accomplish with it. Using a combination of simple commands, we will see how to solve complex problems in day to day computer usage.

Linux Shell Scripting Cookbook, Second Edition will take you through useful real-world recipes designed to make your daily life easy when working with the shell. The book shows the reader how to effectively use the shell to accomplish complex tasks with ease.

The book discusses basics of using the shell, general commands and proceeds to show the reader how to use them to perform complex tasks with ease.

Starting with the basics of the shell, we will learn simple commands with their usages allowing us to perform operations on files of different kind. The book then proceeds to explain text processing, web interaction and concludes with backups, monitoring and other sysadmin tasks.

Linux Shell Scripting Cookbook, Second Edition serves as an excellent guide to solving day to day problems using the shell and few powerful commands together to create solutions.

What you will learn from this book

  • Explore a variety of regular usage tasks and how it can be made faster using shell command
  • Write shell scripts that can dig data from web and process it with few lines of code
  • Use different kinds of tools together to create solutions
  • Interact with simple web API from scripts
  • Perform and automate tasks such as automating backups and restore with archiving tools
  • Create and maintain file/folder archives, compression formats and encrypting techniques with shell
  • Set up Ethernet and Wireless LAN with the shell script
  • Monitor different activities on the network using logging techniques

Approach

This book is written in a Cookbook style and it offers learning through recipes with examples and illustrations. Each recipe contains step-by-step instructions about everything necessary to execute a particular task. The book is designed so that you can read it from start to end for beginners, or just open up any chapter and start following the recipes as a reference for advanced users.

Who this book is written for

This book is both for the casual GNU/Linux users who want to do amazing things with the shell, and for advanced users looking for ways to make their lives with the shell more productive.

You can start writing scripts and one-liners by simply looking at the similar recipe and its descriptions without any working knowledge of shell scripting or Linux. Intermediate/advanced users as well as system administrators/ developers and programmers can use this book as a reference when they face problems while coding.

CSS Cookbook (3rd Edition)

Writing for the Web: Creating Compelling Web Content Using Words, Pictures, and Sound

The Ultimate Guide to WordPress

Mobile and Web Messaging: Messaging Protocols for Web and Mobile Devices

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

complement set. For example: $ echo hello 1 char 2 next 4 | tr -d -c '0-9 \n' 1 2 4 Here, the complement set is the set containing all numerals, the space character, and newline. All other characters are removed since –d is used with tr. Squeezing characters with tr The tr command is very helpful in many text processing contexts. Repeated continuous characters should be squeezed to a single character in many circumstances. Squeezing of whitespace is a frequently occurring task. tr provides the

know, the cat command can be used to read any data and redirection can be used to write to a file. How to do it... In order to create an ISO image from /dev/cdrom use the following command: # cat /dev/cdrom > image.iso This will work, it will read all the bytes from the device and write an ISO image. Using the cat command for creating an ISO image is a tricky way to do it. But the most preferred way to create an ISO image is to use the dd utility. # dd if=/dev/cdrom of=image.iso mkisofs is a

field of every line as follows: $awk '{ print $3,$2 }' file In order to count the number of lines in a file, use the following command: $ awk 'END{ print NR }' file Here we only use the END block. NR will be updated on entering each line by awk with its line number. When it reaches the end line it will have the value of last line number. Hence, in the END block NR will have the value of last line number. You can sum up all the numbers from each line of field 1 as follows: $ seq 5 | awk 'BEGIN{

sum=0; print "Summation:" } { print $1"+"; sum+=$1 } END { print "=="; print sum }' Summation: 1+ 2+ 3+ 4+ 5+ == 15 153 Texting and Driving Passing a variable value from outside to awk By using the -v argument, we can pass external values (other than from stdin) to awk as follows: $ VAR=10000 $ echo | awk -v VARIABLE=$VAR'{ print VARIABLE }' 1 There is a flexible alternate method to pass many variable values from outside awk. For example: $ var1="Variable1" ; var2="Variable2" $ echo | awk '{

example:695208515) epoch UNIX time in seconds %s (for example: 1290049486) 31 Shell Something Out Use a combination of format strings prefixed with + as an argument for the date command to print the date in the format of your choice. For example: $ date "+%d %B %Y" 20 May 2010 We can set the date and time as follows: # date -s "Formatted date string" For example: # date -s "21 June 2009 11:01:22" Sometimes we need to check the time taken by a set of commands. We can display it as follows:

Download sample

Download