Unix/linux System Management Technical Manual Read (11)

Source: Internet
Author: User

2016.11.7

2 Scripting and the Shell

Good system administrators write scripts. Scripts standardize and automate the performance of administrative chores and free up admins ' time for more important and More interesting tasks. In a sense, scripts is also a kind of low-rent documentation in this they act as an authoritative outline of the steps NE Eded to complete a particular task.

Good system administrators have to write scripts. The script performs the tedious business of the system administrator in a standard and automated manner, saving the administrator time to spend on more important and interesting tasks. In a sense, scripts are also a low-quality document because they act as an authoritative outline that outlines the steps required to complete a particular task.

In terms of complexity, administrative scripts run the gamut from simple ones this encapsulate a few static commands to Ma Jor software projects that manage the host configurations and administrative data for an entire site. In this book we ' re primarily interested in the smaller, day-to-day scripting projects that sysadmins normally encounter, s o we don ' t talk much about the functions (e.g, bug tracking and design review) that is needed for larger project S.

In terms of complexity, the range of system administration scripts is simple enough to encapsulate only a few static commands, as large as an important software project, to manage host configuration and administrative data for the entire site. In this book, we are interested primarily in the smaller, everyday scripting projects that system administrators typically encounter. As a result, we don't talk too much about the support features (for example, bug tracking and design reviews) that are needed for large projects.

Administrative scripts should emphasize programmer efficiency and code clarity rather than computational efficiency. This isn't an excuse to being sloppy, but simply a recognition the IT rarely matters whether a script runs in half a second or both seconds. Optimization can has an amazingly low return on investment, even for scripts, the run regularly out of cron.

The system administration script should focus on two points, that is, the programmer's development efficiency and the code's clear readability. Computational efficiency should not be the focus, but it should not be an excuse to act rashly, but to realize that there is little need to care if a script runs out in half a second or two seconds. Optimization scripts get very low returns, even for scripts that run regularly through Cron.

For a long time, the standard language for administrative scripts is the one defined by the shell. Most systems ' default shell was bash (the "bourne-again" shell), but SH (the original Bourne shell) and ksh (the Korn shell) is used on a few UNIX systems. Shell scripts is typically used for light tasks such as automating a sequence of commands or assembling several filters T o process data.

For a long time, the standard language for writing system administration scripts is the language defined by the shell. On most systems, the default shell is bash (the "Bourne agin" shell), but on a few UNIX systems, SH (the original Bourne shell) and ksh (Korn shell) are also used. Shell scripts are typically used for lightweight tasks, such as automating a series of commands, or combining several filters to process data.

The shell is always available, so shell scripts is relatively portable and has few dependencies other than the commands They invoke. Whether or not choose the shell, the shell may choose you:most environments include a hefty complement of existing SH Scripts, and those scripts frequently need to is read, understood, and tweaked by administrators.

Shell scripts are available on various operating systems, so the shell script can be very well-shifted, with few things to rely on except the commands they invoke. The shell is encountered whether or not the shell is selected, and most environments include a powerful complement to the existing SH scripts, which are frequently read, understood, and adjusted by system administrators.

For more sophisticated scripts, it's advisable to jump to a real programming language such as Perl or Python, both of whic H is well suited for administrative work. These languages incorporate a couple of decades ' worth of language design advancements relative to the shell, and their te XT processing facilities (invaluable to administrators) is so powerful this sh can only weep and cower in shame.

for more complex, high-end scripts, it is recommended to move to a real programming language, such as Perl or Python, both of which are well suited for system administration. The two languages incorporate a design concept that is ahead of the shell in the 20, and their word processing capabilities (which are invaluable to system administrators) are so powerful that SH is eclipsed by them.

The main drawback to Perl and Python are that their environments can be a bit

Fussy to set-up, especially if you start with use Third-party libraries that has compiled components. The shell skirts This particular issue by have no module structure and no Third-party libraries.

The main disadvantage of Perl and Python is that it is a bit of a hassle to build their environment, especially for third-party libraries, which contain compiled parts. The shell has no module structure and no third-party libraries, so it avoids this particular problem.

This chapter takes a quick look at bash, Perl, and Python as languages for scripting, along with regular expressions as a General Technology.

This chapter provides a brief introduction to the use of Bash, Perl, and Python as scripting languages and the generic technique of regular expressions.


2.1 SHELL BASICS

Before we take up shell scripting, let ' s review some of the basic features and syntax of the shell. The material in this section applies to all major shells in the Sh lineage (including bash and ksh, but not csh or tcsh), Regardless of the exact platform you is using. Try out the forms you ' re not familiar with, and experiment!

Basics of 2.1 Shell

Before we start introducing shell script editing, let's look at one of the basic features and syntax of the shell. Regardless of which platform the reader is using, this section applies to all major shell (including bash and ksh, but not csh or Tesh) in the Sh family. Try your own unfamiliar sh form and do the experiment!


This article is from the "Zhao Dongwei blog" blog, make sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1870335

Unix/linux System Management Technical Manual Read (11)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.