Linux - Why shell scripting

Why shell scripting?

  • Shell scripts can take input from a user or file and output them to the screen.
  • Whenever you find yourself doing the same task over and over again you should use shell scripting, i.e., repetitive task automation.
    • Creating your own power tools/utilities.
    • Automating command input or entry.
    • Customizing administrative tasks.
    • Creating simple applications.
    • Since scripts are well tested, the chances of errors are reduced while configuring services or system administration tasks such as adding new users.

Practical examples where shell scripting actively used

  • Monitoring your Linux system.
  • Data backup and creating snapshots.
  • Dumping Oracle or MySQL database for backup.
  • Creating email based alert system.
  • Find out what processes are eating up your system resources.
  • Find out available and free memory.
  • Find out all logged in users and what they are doing.
  • Find out if all necessary network services are running or not. For example if web server failed then send an alert to system administrator via a pager or an email.
  • Find out all failed login attempt, if login attempt are continue repeatedly from same network IP automatically block all those IPs accessing your network/service via firewall.
  • User administration as per your own security policies.
  • Find out information about local or remote servers.
  • Configure server such as BIND (DNS server) to add zone entries.

Shell scripting is fun. It is useful to create nice (perhaps ugly) things in shell scripting. Here are a few examples of scripts I use everyday:

  • Find out today's weather (useful when you are busy in a chat room).
  • Find out what that site is running (just like netcraft).
  • Download RSS feeds and display them as you login or in your email.
  • Find out the name of the MP3 file you are listening to.
  • Monitor your domain expiry date every day.

Advantages

  • Easy to use.
  • Quick start, and interactive debugging.
  • Time Saving.
  • Sys Admin task automation.

Disadvantages

  • Compatibility problems between different platforms.
  • Slow execution speed.
  • A new process launched for almost every shell command executed.
  • Shell scripts can execute without any additional effort on nearly any modern UNIX / Linux / BSD / Mac OS X operating system as they are written an interpreted language.

Which Shell are we going to use in this tutorial?

  • Bash shell.

Learning Objectives

After completing this tutorial, you will be able to:

  • Understand the basis of Linux shell scripting.
  • Write shell scripts and use it to save time with automated scripts.
  • Customize shell start-up files.
  • Create nifty utilities.

Source: https://bash.cyberciti.biz/guide/Why_shell_scripting