20.1 Shell Script Introduction
What is a shell?
shell是一种脚本语言 aming_linux blog.lishiming.net可以使用逻辑判断、循环等语法可以自定义函数shell是系统命令的集合shell脚本可以实现自动化运维,能大大增加我们的运维效率
20.2 shell script Structure and execution
开头需要加#!/bin/bash以#开头的行作为解释说明脚本的名字以.sh结尾,用于区分这是一个shell脚本执行方法有两种chmod +x 1.sh; ./1.shbash 1.sh查看脚本执行过程 bash -x 1.sh查看脚本是否语法错误 bash -n 1.sh
20.3 Date Command usage
date??+%Y-%m-%d, date +%y-%m-%d 年月日date??+%H:%M:%S = date +%T 时间date +%s??时间戳date -d @1504620492date -d "+1day" 一天后date -d "-1 day" 一天前date -d "-1 month" 一月前date -d "-1 min" 一分钟前date +%w, date +%W 星期
Operation Process
[[email protected] ~]# date2018 April 22 Sunday 21:12:09 cst[[email protected] ~]# date +%y2018[[email Protected] ~]# Date +%y18[[email protected] ~]# date +%m04[[email protected] ~]# date +%m12[[email Protected] ~]# Date +%d22[[email protected] ~]# date +%d04/22/18[[email protected] ~]# date +%y%m%d20180422[[ Email protected] ~]# date +%f2018-04-22[[email protected] ~]# date +%h21[[email protected] ~]# date +% S1524402829[[email protected] ~]# date +%s54[[email protected] ~]# date +%t21:15:14[[email protected] ~]# date +%h4 Month [[email protected] ~]# date +%w0[[email protected] ~]# date +%w16[[email protected] ~]# cal April 2018 1,234,561 2 3 4 5 6 7 8 9 ten-1415-2122-2829 30[[email protected] ~]# lang=en_us[[email protected] ~]# datesun Apr 21:25:46 CST 2018[[email protected] ~]# da Te-d "-1 day" Sat Apr 21:26:18 CST 2018[[email p rotected] ~]# date-d "-1 day" +%f2018-04-21[[email protected] ~]# date-d "-1 month" Thu Mar 21:26:36 CST 2018[[ Email protected] ~]# date-d "-1 year" Sat APR 21:27:56 CST 2017[[email protected] ~]# date-d "-1 hour" Sun Ap R 20:28:05 CST 2018[[email protected] ~]# date-d "-1 hour" +%f2018-04-22[[email protected] ~]# date-d "-1 h Our "+%t20:29:01[[email protected" ~]# date +%s1524403788[[email protected] ~]# date-d @1524403788Sun APR 22 2 1:29:48 CST 2018[[email protected] ~]# date +%s-d "2018-04-22 21:29:48" 1524403788
20.4 variables in a shell script
2018-05-29 Linux Learning