Label: Bash script
Shell is a scripting language for control systems. Bash is one of the shell interpreter and the most popular one in Linux. However, there are many shell interpreters, and each type has its own characteristics, not exactly the same ..,
Common shell:
Sh, CSH, tcsh, Bash, KSh, Dash, zsh
Co
Write a robust bash scriptMany people use shell scripts to accomplish simple tasks and become part of their lives. Unfortunately, shell scripts can be very much affected by running exceptions. It is necessary to minimize such problems when writing scripts. In this article I'll cover some of the techniques that make bash scripts robust.Using Set-u www.ahlinux.comH
Write a test script:Input Start command: test.sh, result errorThe root user is used, but the permissions are still insufficient.Input/bin/sh test.sh, you can start the script, but the syntax error:Error message The loop variable is not correct. Baidu a bit this error, explained as follows:
Because Ubuntu is replacing the traditional bash with dash in order
these problems, it is great to either delete the lock file or roll back to a known state when the script encounters a problem. Fortunately, Bash provides a way to run a command or a function when bash receives a UNIX signal. You can use the Trap command.
Trap command signal [signal ...]
Multiple signals can be linked (lists can be obtained using kill-l), but i
Write a bash shell scriptThe script is as follows: it is used to monitor the number of mongo connections and restart the system.#! /Bin/bash# Source/etc/profileConn = '/usr/bin/mongo -- quiet Db. serverStatus (). connectionsExitEOF`Conn1 =$ {conn #*:}Curr =$ {conn1% ,*}# PID = $ (ps-ef | grep "mongodb" | grep-v grep |
Fun Bash Script: numerical calculation, bash script Numerical Calculation
6th articles
The mathematical operations in Bash are not as simple as other languages, because Bash treats all variables as strings, so a = 1 + 2, a is not
must be followed by a reserved word then. You can also write them in the same line, but note that they should be separated by semicolons. These bash interpreters know that then is not part of the if condition. Otherwise, an error is reported.
If
Example of Writing test and [] conditions
Enter a number and determine whether it is less than 100
#! /Bin/bashread-p "enter a number:" aif [$ a-lt 100] then ec
values of the shell options and positional parameters.5. Position variablesCalling parameters passed to the script from the command line in the script$, $ ... : corresponding to the command line of the 1th, 2nd ... A parameter$: Command itself$*: All parameters passed to the script, all parameters as a whole[Email protected]: All parameters passed to the
Bash script skills-trap Command, bash script-trap
Share a shell script technique. When you write a shell script, you generally only ensure that the function is available, but the progr
Linux bash integrated instance bash Script Editor, linuxbash
Note: This is a simple bash Script Editor, but it has been tested. The reason for writing this blog is to exercise loop control language, functions, location parameters, local variables, function parameter calls, a
Advanced Bash script, classic usage and cases, advanced bashIn linux, Bash scripts are very basic knowledge. You may feel very high when you listen to the scripts. Just like starting from the beginning, you may feel that script writing is a great tool. Although complicated scripts are very easy to understand, when we m
protected] ~]# pwd[Email protected] ~]# first.sh##/etc/fstab# Created by Anaconda on Sun June 21 02:15:00 2015## Accessible filesystems, by reference, is maintained under '/dev/disk '# See mans Pages Fstab (5), Findfs (8), mount (8) and/or Blkid (8) for more info#/dev/null: Software device, bit bucket, data black hole$?[[email protected] ~]# ID student >/dev/null[[email protected] ~]# echo $?1[[email protected] ~]# ID rhel >/dev/null[[email protected] ~]# echo $?0[Email protected] ~]#The
SHELL script strategy (learning notes) -- 1.5 bash environment configuration process, -- 1.5 bash
From the perspective of user login, shell is divided into two types:
Logon shell: If you log on through a terminal, use the su-username command to switch users.
Non-interactive shell: for example, you can use the su username command to switch between users. Open the
Description : This is a relatively simple bash script editor, but has been tested. The reason for writing this blog is to practice the loop control language, functions, positional parameters, local variables, and function parameter calls, as well as calls between functions, as well as parameters for obtaining user options and options.Note: The script options and
Bash script exercises and bash scripts
Exercise 1:
1. Add five users, user1,..., user5;
2. The password of each user is the same as the user name. After the password is added, the command execution result is not displayed;
3. After each user is added, it must be displayed that the user has been added successfully.
Useradd user1
Echo "user1" | passwd -- stdi
Description : This is a relatively simple bash script editor, but has been tested. The reason for writing this blog is to practice the loop control language, functions, positional parameters, local variables, and function parameter calls, as well as calls between functions, as well as parameters for obtaining user options and options.Note: The script options and
Sometimes you write scripts with errors that are listed like headings, mostly because your script files are edited under Windows. Windows, the end of each line is \n\r, and in Linux under the end of the file is \ n, then you edit the file in Windows under Linux open to see the end of each line will be more than one character \ r, Cat-a Urfile you can see this \ The r character is displayed as a ^m, and it i
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.