CopyCodeThe Code is as follows: #/bin/bash
# History
# Paste the following code directly to/etc/profile.
User_ip = 'Who-u am I 2>/dev/null | awk '{print $ NF}' | sed-E's/[()] // g''
Histdir =/var/log/. hist
If [-Z $ user_ip]
Then
User_ip =
I. define functions
CopyCodeThe Code is as follows: function fname ()
{
Statements;
}
OrCopy codeThe Code is as follows: fname (){Statements;}
Ii. Call Functions
You can call a function by using the function name:$ Fname; # execute a
Shell also has a real debugging mode. If an error occurs in the script "strangescript", you can debug it as follows:
Sh-x strangescript
This will execute the script and display the values of all variables.
Shell also has a mode that only checks
Copy codeThe Code is as follows: # include
Using namespace std;
Void ShellQin (int A [], int n)
{
Int gap = n/2;
Int I, j;
For (; gap> 0; gap = gap/2) // set the initial gap, group by gap, and decrease by gap/2
{
// After the gap is set, insert and
This e-mail alert script is widely used. Many of the sendmail and postfix scripts are used, and some of them are used in perl's NET: SMTP and Authen: SASL modules, but I am not using perl well. I always send some inexplicable emails (such as if (a> 1
Copy codeThe Code is as follows :#! /Bin/sh
# Obtain the date interval from the first day of the quarter to yesterday
# Link: www.jb51.net
# Date: 2013/2/28
Day = 'date-d "1 days ago" "+ % Y % m % d "';Year = 'expr substr $ {day} 1 4 ';Month =
Extract the alert log shell script of oralce on the current day
Copy codeThe Code is as follows: #/bin/sh
# Get alert of everyday
# Then name of file is everyday_alert.sh
Dir = "/oracle/admin/bbdz/bdump"
Num = $ (cat-n $ {dir}/alert_bbdz.log |
Back up website content
Copy codeThe Code is as follows :#! /Bin/bash
# Specify the running script shell
# Run the script to grant the user the execution permission
Bakdir =/backup
Month = 'date + % m'
Day = 'date + % d'
Year = 'date + % y'
1. print some header informationCommand ............Dilimiter
Use the content in the demarcation symbol dilimiter as the standard input of the commandIt is often used in echo commands, which avoids the use of an echo command when no line is output,
Copy codeThe Code is as follows :#! /Bin/bash
# This script is used for describle CPU Hard Memery Utilization
Total = 0
Idle = 0
System = 0
User = 0
Nice = 0
Mem = 0
Vmexec =/usr/bin/vmstat
Which sar>/dev/null 2> & 1
If [$? -Ne 0]
Then
Ver = 'vmstat-
1. define the shell function (define function)
Syntax:[Function] funname [()]{Action;[Return int;]}Note:1. It can be defined with function fun () or fun () without any parameters.2. If the parameter is returned, the value "+: return" is displayed.
Copy the files in the bill folder to the bill1 and bill2 folders according to certain rules (file name parity.Update the progress tag of bill1 and bill2 (Update file. max)File3 is the label of the latest file under the bill directory. It is updated
Copy codeThe Code is as follows :#! /Bin/bash
#********************************#
# Run fun in the concurrent background #
# For wanggy 2012-01-25 #
# Note :#
# Fun_num number of times the fun function runs in the background #
# SQL _num SQL
Copy codeThe Code is as follows :#! /Bin/bash
# Telno is used to query the number list file
# Sendsms. log is the text message sending result File
#1 indicates that the message is successfully sent.
Query_sms ()
{
> Submit_telno
>
1. Character truncation:
For normal path truncation, you can use the basename and dirname tools:Basename can intercept a file name from a file path.
For example:
Copy codeThe Code is as follows: $ basename/home/file.tar
File.tar
Dirname can be
For example, to require scripts to only access a certain resource in sequence, such as disk files, you can refer to the following implementation.
Copy codeThe Code is as follows :#! /Bin/bash
#
# File locking using bash.
# Ver 0.1.6
#
# Author:
Compare shell strings and determine whether the string is a number
Binary comparison operator, which compares variables or numbers. Note the difference between numbers and strings.
Integer comparison
-Eq equals to, for example, if ["$ a"-eq "$ B"]
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