Shell exercises (14)

Exercise 1:Print a line with only one numberRequirements: title, a text document with only a number of lines to print outReference Answer:#!/bin/bash# date:2018 March 16 f=/etc/groupline= ' wc-l $f |awk ' {print $} ' for L in ' seq 1 $line ' do n= '

How shell scripts are executed

method One: Switch toShellthe directory where the script is located (at this time, called the working directory) executesShellScript:Cd/data/shell./hello.shThe./ means to execute hello.sh under the current working directory . If you do not add

The second week of Linux learning; shell programming

Pstree-p #显示进程编号 (tree) echo $$ basic structure of #显示当前shell进程编号   scripts: #! Shebang (indicates what shell is used to open a file, typically using bash) configuration_variables #定义变量FUNCTION_DEFINITIONS # define function Main_code #主要执行命令  

Shell functions use

function definition Format:It's a bit like JS, but the function keyword is optional in the shell.Such as:sum{ //Shell statement}  function sum () { //Shell statement}Function Call Method:Sum parameter 1 parameter 2 ...  Get function Parameters:

The use of if,case,for in shell scripts

DirectoryI. Condition selection: If statementTwo. Conditional judgment: Case statementThree. For loopI. Condition selection: If statement Single Branchif judgment condition; thenBranch code with true conditionFiExample: Judging whether a number

Linux Shell daemon/RAC Restart script

To establish a daemon process:#! /bin/sh PRO_NAME=./xxxx.sh while true ; do #用ps获取$PRO_NAME进程数量 echo ‘‘> nohup.out NUM=`ps aux | grep -w ${PRO_NAME} | grep -v grep |wc -l` #echo $NUM #少于1,重启进程 if [ "${NUM}" -lt "1"

Shell Exercises (vii)

Exercise 1:Statistics Log size If we need to execute the script you wrote every hour. In the script to implement such a function, when the time is 0 and 12 points, you need to empty the file under directory/data/log/, notice can only empty the

Shell Scripting Exercises

Title requirements:Write a script to enter personal information/root/bin/information.sh, the requirements are as follows:1. Prompt the user to enter username (need to check the name of the character, the user name can not be blurred contains any of

Shell Exercises (vi)

Exercise 1:Enter a number to execute the corresponding commandRequirements: Enter a number and then run one of the corresponding commands. The commands shown are as follows: *cmd meau* 1-date 2–ls 3–who 4–pwd; when input 1 o'clock, run date, enter 2

Shell programming Exercise-Copy the specified file (keep the directory structure of the file)

1. PurposeCopy all files larger than 1M (customizable) in the/root directory to the/tmp/bakdir (customizable) directory, and you need to keep the directory structure.For example, the/root/reed.file file size is 12M and will be copied to

Judge the CentOS system version of the shell

Routine maintenance requires a generic execution shell, but the CentOS 6 version is different from the 7 version of the command, and needs to be judged by the program itself, as follows:1. View cat/etc/centos-release[Email protected]/0 #

Shell Exercises (v)

Exercise 1:Delete the letters in the textRequirements: Delete the line containing the letters in the first 5 lines of a text document and delete all the letters from 6 to 10 lines (file 1.txt, lines greater than 10 lines)Reference Answer:#!/bin/bash#

One shell per day (eight) Nginx log cutting

Nginx log will increase with the amount of traffic, the larger log will affect the analysis log when the analysis and processing, we can use the shell to the Nginx log timing segmentation, to weeks or days, for a long time log can be deleted

Linux timed Execution Shell script command crontab

Crontab can execute a shell script and execute a series of Linux commands at a specified timeExample: Server administrator regularly backs up database data, logs, etc.DetailedCommon commands:Crontab–e //Modify the crontab file, if the file does

Write a shell script and execute it once

First the CD into a directoryTauch tset.sh//Create a new test.sh fileVim test.sh Edit ScriptI insert#!/bin/bashDataPress the ESC keyThen press CTRL +:Wq + EnterLs-l test.sh//view file permissions-rw-rw-r--1 Elasticsearch elasticsearch 18 February 8 1

Shell programming------variables, assignments, and operations

1. Variable assignment:NAME=LBG equals sign cannot have spaces name= "Lebron James" variable values have spaces in double quotes Echo ${name} with ${} More insurance shopt-s-O Nou Nset setting "Declare and use first"2. Cancel the variable:unset

Linux Shell Learning Notes

The first line of the shell script illustrates the path to the interpreter: #!/bin/bashRun the script two ways: Use the bash command to run the shell file, or grant the script file execution permissions, you can directly execute the fileWhen the

Shell Distribution System

Rsync.expect#!/usr/bin/expectset passwd "123456" # #建议用密钥 to prevent password disclosure set host [lindex $argv 0]set file [lindex $argv 1]spawn R SYNC-AVR--files-from= $file/[email protected] $host:/expect {"yes/no" {send "yes\r"} "Password:" {send

Linux Basics-Shell arrays

Summary The attribute of an array is a set of identical data types, although the shell is a weak type, but we can also divide its array into 数据类型的数组 字符串类型的数组 two categoriesSeparating the shell array elements from each other 空格

$0, $? In Shell scripts? , $! , $, $ *, $ #, $ @, Etc.

$0, $? In Shell scripts? , $! , $, $ *, $ #, $ @, Etc. $0 indicates the execution name of the program. The file name of the current script $ n indicates the nth parameter value of the program. n = 1 .. 9 $ * all parameters of this program. This

Total Pages: 541 1 .... 400 401 402 403 404 .... 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.