In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
[TOC]
First, DAY61.shell script introduction shell is a scripting language aming_linux blog.lishiming.net can use logic judgment, loops and other syntax to customize functions shell is a collection of system commands shell script can achieve automated operation and maintenance, can greatly increase our operation and maintenance efficiency 2.shell script structure and the beginning of execution need to add #! / bin/bash, which is the inherent format of shell, specify the next command to run Lines that begin with # are explained by that interpreter. Some lines starting with the # script # have a specific role #! / bin/bash# chkconfig: 2345 10 90 defines the startup level, and the two lines must be # description: Activates/Deactivates all network interfaces configured to\ description information. Without these two lines, you cannot add # start at boot time to the chkconfig list. # the name of the script ends with .sh, which is used to distinguish whether it is a shell script. There are two ways to execute it: chmod + x 1.sh . / 1.shbash 1.sh script execution can be done with bash or sh [root@mydb1 test] # ls-l / bin/sh lrwxrwxrwx 1 root root 4 Apr 24 2019 / bin/sh-> bash [root@mydb1 test] # ls-l / bin/bash-rwxr-xr-x 1 root root 906568 Mar 23 2017 / bin/bash View script execution bash-x 1.sh to see if the script has syntax errors bash-n 1.sh can only check syntax errors 3.date command usage date +% Y-%m-%d Date +% y-%m-%d date +% H:%M:%S = date +% T time date +% s timestamp date-d @ 1504620492date-d "+ 1day" one day later date-d "- 1day" one day ago date-d "- 1 month" one month ago date-d "- 1 min" a minute ago
Date +% w, date +% W week
Demo:
[root@mydb1 test] # date +% y abbreviation 19 [root@mydb1 test] # date +% Y 2019 [root@mydb1 test] # date +% m November 11 [root@mydb1 test] # date +% M score 40 [root@mydb1 test] # date +% d 20 [root@mydb1 test] # date +% D month / day / 11-20-19 [root@mydb1 test] # date +% Y%m%d date 20191120 [root@mydb1 test] # date +% F-month-day 2019-11-20 [root@mydb1 test] # date +% H 11 [root@mydb1 test] # date +% s timestamp 1574221403 [root@mydb1 test] # date +% S seconds 30 [root@mydb1 test] # date +% T: minutes: 11:49:36 [root@mydb1 test] # date +% h English month Nov [root@mydb1 test] # date +% H:%M:%S equals T11root@mydb1 test 52date 40 [root@mydb1 test] # date +% w Day 3 [root@mydb1 test] # date +% W Calendar week of the year 46 [root@mydb1 test] # cal Calendar form November 2019 Su Mo Tu We Th Fr Sa 12 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 26 27 28 29 30 [root@mydb1] # date +'% Y% m% d'-d' 1 days ago' 20191119 [root@mydb1 ~] # date +'% Y% m% d'-d'-1 days' 20191119 [root@mydb1 ~] # date +% F-d' 1 year' one year later 2020-11-20 [root@mydb1 ~] # date +% F-d'-1 year' 1 year ago 2018-11-20 [root@mydb1 ~] # date +% T 13:55:03 [root@mydb1 ~] # date +% T-d'- 1 hour' 1 hour ago 12:55:18 [root@mydb1 ~] # date +% s 1574229561 [root@mydb1 ~] # date-d @ 1574229561 convert the timestamp to a specific date Wed Nov 20 13:59:21 CST 2019 [root@mydb1 ~] # date +% s-d "2019-11-20 14:01:01" convert the specific time to the timestamp 15742296614.shell script Variables in a script should use variables instead of conditional statements when a string is used more frequently and the string length is very long Frequently used variable if [$a-gt 1] When then...; fi refers to the result of a command and replaces n = `wc-l 1.txt` to write scripts that interact with users, variables are also essential: read-p "Input a number:" n; echo $n if you don't write this n, you can directly use the $REPLY built-in variables $0, $1, $2... $0 represents the script itself, $1 first parameter, $2 second. $# denotes the number of parameters in mathematical operations: aplomb (($astatb)) or logical judgment format 1:if condition in 5.shell script; then statement; fidelity bind bind 5if [$a-gt 3] then echo okfi format 2:if condition; then statement; else statement; fiduciary binvocation then echo okelse echo nookfi 2if [$a-gt 3] then echo okelse echo nookfi format 3:if … ; then... ; elif... ; then... ; else... ; fidelity binder gt gt 3if [$a-eq 4] then echo "> 1" elif [$a-lt 6] then echo "1" else echo nookfi logical judgment expression: if [$a-gt $b] if [$a-lt 5] if [$b-eq 10]-gt (>);-lt (=);-le (
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.