SHELL脚本编程进阶(2)及Centos启动流程

1、用shell脚本实现自动登录机器

#!/usr/bin/expect
spawn ssh 192.168.34.128
expect {
        "yes/no" {send "yes\n";exp_continue}
        "password" {send "YOUR PASSWORD\n"}
}
interact

2、shell 判断一个值bone是否在数组arrayZ=( one two three four five five )中

#!/bin/bash
arrayZ=(one two three four five bone)
for i in `seq 0 $[${#arrayZ[*]}-1]`;do
{
        if [[ "${arrayZ[$i]}" =~ "bone" ]];then
                echo "bone is in arrayZ"
                exit
        else
                let i++
                continue
        fi
}
done
echo "bone is not in arrayZ"

3、用命令或者脚本实现 0057AF051EFF 变为 00:57:AF:05:1E:FF 。

#!/bin/bash
ori="0057AF051EFF"
mac=""
while [ -n "$ori" ];do
{
        mac="$mac${ori:0:2}:"
        ori="${ori:2}"
}
done
mac="${mac%:*}"
echo "$mac"

4、a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9 0 ! @ # $ % ^ & * ( ) - _ = + \ / ' " ; : [ ] { } , . ?
用以上字符,结合数组,实现一个随机生成20位密码的脚本

#!/bin/bash
word=(a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L
M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9 0 \! \@ \# \$ \% \^ \& \* \( \) \- \
_ \= \+ \\ \/ \' \" \; \: \[ \] \{ \} \, \. \?)
for((i=0;i<20;i++));do
{
        echo -n "${word[$[RANDOM%${#word[*]}]]}"
};done
echo

5、Centos7开机流程
(1)POST加电自检,并选择引导设备
(2)进入引导设备后,在第一个扇区(MBR)前446字节找到引导程序grub2,此为grub第1阶段;通过grub第一阶段找到的进入/boot分区所需的驱动,并识别/boot分区。此为grub第1.5阶段;进入/boot目录后,通过/grub2/grub.conf,加载内核,此为grub第2阶段
(3)内核初始化,然后开始运行systemd,选择对应的target。
6、编写Nginx的systemd配置文件, 实现nginx进程开机启动


你可能感兴趣的:(SHELL脚本编程进阶(2)及Centos启动流程)