If we need to restrict a Linux user to use only the commands we specify, we can use the restricted shell.Use in a normal command environment:Test: # bash-r # Enter the restricted shell# cd/bash:cd:restricted# exitSpecific settings:# useradd test
1. File operationCP MV MkDir CatTouch creates a new file, changes the last modified dateSource makes the file effective immediatelyWc-l the number of rows in the filename statistic file2. System commandsWHO displays user information currently logged
Write an SSH anti-violence hack script.The principle is to detect the SSH connection log, filter the login failed IP, more than the number of login to add it into the Hosts.deny file, limit its login.The script is as follows:#! /bin/bashcat /var/log/
According to company requirements, delete the server 30 days before the file, the following is the script:#vi del-30.sh#!/bin/bashlocation= "/mpgdata/"Find $location-type f-mtime +30-exec rm-f {} \;#chmod +x del-30.shDescription:/mpgdata/is the path
Variable Description:$$The PID of the shell itself (ProcessID)$!PID of the Shell's last running background process$?End code of the last Run command (return value)$-Flag at a glance using the SET command$*All parameter lists. such as "$*" in the
#! /bin/shA= "Hello World"echo "A is"Echo $aecho ""echo "A is $a"Results of the output:A isHello WorldA is Hello World2 Getting the system time:Get today's period: ' Date +%y%m%d ' or ' date +%f ' or $ (date +%y%m%d)Get yesterday's period: ' Date-d
A few examples of shell scripts, feel good." Example: 001 " judging the input as a number, character or other #!/bin/bashread-p ' Enter a number or string here: ' Inputcase $input in [0-9] ' echo-e ' good job, Your input is a numb eric! \ n ";
Impression, always think that as long as mastering the Linux command, natural for writing shell scripts will not be unfamiliar. This is not right. The first half of the sentence is true, it is necessary to master the Linux command, so as to write
The nature of the test:is an action commandDetermine if the condition is true based on the $? return valueOperating Specifications:Format 1:test conditional expressionFormat 2: [Conditional expression]Contact method for the test operation:Direct
Test structure:The test command can be used to test the true and false of the expression condition, and returns0,false, which is not 0; format:Test expression #expression是一个表达式, the expression can be compared by numbers, strings, text and file
&& operators:Command1 && Command2&& the command on the Left (command 1) returns True (that is, returns 0, executed successfully) and the command (Command 2) on the right side of the,&& can be executed, in other words, "If this command succeeds &&
This article references: Shell Scripting Learning GuideThis article reads as follows: Know the shell directive, but do not know how to complete an automated shell script.Because when editing this article, the author is also a novice. So, in some
37. Adjust the properties of a variable
Read-only variable: use the readonly commandReadOnly variable Name
ReadOnly Other uses
ReadOnly or readonly-p: Displays a list of variables that currently have read-only properties
This article references: Shell Scripting Learning GuideThis article reads as follows: Know the shell directive, but do not know how to complete an automated shell script.Because when editing this article, the author is also a novice. So, in some
The shell determines whether the file, directory exists, or has permissions#!/bin/sh mypath= "/var/log/httpd/" myfile= "/var/log/httpd/access.log" #这里的-x parameter Judging $ Whether the MyPath exists and has enforceable permissions if [!-X '
At work, there are times when you need to process some data, use Java to compare aspects, such as hbase, but you need to execute it in the shell, so the extra bag is harder to get into, and it's easy to package with Maven.
First Pop.xml
Shell exits and returns a summary.
Common Responses in shell: exit, breakm, return
Exit:
In fact, after each command is executed, an execution state is returned!
If the execution is successful, 0 is returned.
If the execution limit is not
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