Examples of Linux shell scripts

Shell scripting is the most basic knowledge of our OPS management, and here are a few examples of my learning process (compared to Daniel). The purpose of this blog is to record the course of learning scripts, but also to be able to discuss learning

Linux Automated Format partitioning method (non-interactive, can be used for Shell scripting)

Automated Format Partitioning method ---- non-interactive --- available for scriptingTo give the user a hint first, let him select a partition to formatFor i in ' mount|grep '/dev/sdb ' |awk ' {print '} 'Dofuser–km $i; Umount $iDoneDD If=/dev/zero

Shell Parameter Expansion

Using sh to write some small scripts will make the work easier, and some content may be unfamiliar to everyone (at least I am ),It is variable-related parameter expansion. Below are some simple descriptions and usage, which can make the code more

Shell script parsing 4 ---- branch statement (IF)

I. Condition statements 1, If [expression] Then # Code block Fi 2, If [expression] Then # Code block Else # Code block Fi 3, If [expression] Then # Code block Else if [expression] # Replace this field with Elif [expression] Then # Code block Else #

Shell script parsing 10 (Exercise 4) ------ monitoring File

#! /Bin/bash # Determine whether the command line contains parameters with two file namesIf ["$1" = ""] | ["$2" = ""]ThenEcho "Please enter file name"Exit 1Fi # Determine whether the target file existsIf [-e $2]ThenEcho "the file already

Shell script parsing 9 (Exercise 3) ------ reverse output

#! /Bin/bash # Prompt user input Echo-n "Please enter number" Read N # Put the input value into Variable N SD = 0 REV = "" On = $ N # Save the value of Variable N to the variable on for later use Echo "you put number is $ N" While [$ n-GT 0]

Shell command interface of the storage system based on key/value + hadoop HDFS

Parse all commands in hadoop HDFS (the operation process is your own idea. You are welcome to correct them) Interface Name Function Procedure Get Copy the file to the local file system. If multiple source files are

Shell outputs color text on the terminal

Echo-e "\ e [1; 31 m This is red text \ e [0 m" \ E [1; 31 m set the color to red, \ e [0 m "will reset the color. Each color has a corresponding color code, resetting 0, black 30, red 31, green 32, Blue 34, Magenta 35, cyan 36, white 37 To set

Hadoop shell command Overview

Hadoop supports command line operations on the HDFS file system, and supports shell-like commands to interact with HDFS file systems. For most programmers, shell-like command line operations are quite familiar, in fact, this is also one of the great

Regular Expression in Shell

I. Regular Expression description · Concept: Describe data with common attributes with a string of characters · Note: when using regular expressions for matching, be sure to use the \ transfer symbol. · Format: A. grep [Option] 'regular expression'

[Shell] modifying XML content

It is easier to parse and modify XML using python, but if it is not convenient to use python, you can simply replace it with the SED command For example, to replace the value of the port number in the following line: 21 You can use: New_port =

Shell script basics ----- For Loop

Format For name in list Do Loop body Done Example: List the usernames, uid, and shell in the/etc/passwd file, Row 1, 3, 6, and

Tips for getting parameters from shell scripts

The problem is as follows: perform a loop based on the number of Script Parameters $ #, and output each parameter $1 $2 $3 in sequence ...... I have a loop variable I $ I. When I get this variable I is 1, I want to use this 1 and then call $1, that

In bash shell script programming, how can I correctly obtain "script option Parameters" and "Script Parameters?

Some linnux commands have very powerful functions, mainly because they support many Command Options. For example, the [IP] command can be used to configure and manage IP addresses and route entries. This command can complete all the functions

Example of a shell with Parameters

#! /Bin/bash # program: # lzsh server log filter # History: #2014/07/01 Kom first release #2014/07/03 Kom remote and multi-Param support # Set pathpath =/bin:/sbin: /usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Binexport path # Set Script

Email Alert shell script

Note: you must first install an email server such as Postfix or Sendmail. 1. Apache #!/bin/bash#apache.shnc -w2 localhost 80 if[ $? -ne 0 ]thenecho "apache is down,please check" | mail [email protected] -s "apache is

What are the differences between shell, console & terminal?

Answer 1:The shell is a typical UNIX program. It reads commands from the standard input and prints something on the standard output. This is simple and good. The points is: In a graphical environment (like gnome or KDE) a program cannot just write

Shell: process hierarchy

[[Email protected] ~] $ PS-Ef | grep initRoot 1 0 0 apr24? 00:08:25 init [3] [[Email protected] ~] $ PS-Ef | head-N 1Uid pid ppid C stime tty time cmd   The second and third columns are the current process ID and parent process ID. P1: process 0

Shell Command Line shortcut

In the shell command terminal, Ctrl + n is equivalent to the downward direction key, and Ctrl + p is equivalent to the upward direction key. You can use them or the arrow keys in the Command terminal to quickly find historical commands. This is

Automatically build local yum shell script final version ps real machine Virtual Machine

This small program is simple, but it is the first shell script written by the novice. It has many factors to consider, but some errors are not handled ,, #! /Bin/bash# Auth: dhh Clear Addr =/etc/yum. repos. d Mkdir $ addr/bf>/dev/null 2> & 1 Mv $

Total Pages: 541 1 .... 496 497 498 499 500 .... 541 Go to: GO

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.