第八周作业

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

#!/usr/bin/expect

set usr root
set pwd 123456
set ipadd 10.0.0.203
spawn ssh $usr@$ipadd
expect {
    "yes/no" { send "yes\n";exp_continue }
    "password" { send "$pwd\n" }
}
interact

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

#!/bin/bash

arrayZ=( one two three four five five bond )
for i in `seq ${#arrayZ[*]}`;do
echo ${arrayZ[$i-1]}
if [ ${arrayZ[$i-1]} == bond ];then
    echo bond in arrayZ
else
    echo bond not in arrayZ
fi
done

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

#!/bin/bash

Mac=0057AF051EFF
for i in `seq 0 2 10`;do
    if [ $i -eq 2 ];then
        echo -n "${Mac:$i:2}"
    else
        echo -n "${Mac:$i:2}:"
    fi

done
echo ${Mac:0:2}:${Mac:2:2}:${Mac:4:2}:${Mac:6:2}:${Mac:8:2}:${Mac:10}

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

declare -a num
num=(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 in `seq 20`;do
    let i=$[$RANDOM%${#num[*]}]
    echo -e "${num[$i]:0:20}\c"
done

5、详细叙述centos7开机流程

POST --> Boot Sequence --> Bootloader --> kernel + initramfs(initrd) --> rootfs --> /sbin/init
    init:    CentOS 5  SysV init
        CentOS 6  Upstart
        CentOS 7  Systemd

CentOS7引导顺序
    UEFi或BIOS初始化,运行POST开机自检
    选择启动设备
    引导装载程序, centos7是grub2
    加载装载程序的配置文件:
        /etc/grub.d/
        /etc/default/grub
        /boot/grub2/grub.cfg
    加载initramfs驱动模块
    加载内核选项
    内核初始化,centos7使用systemd代替init
    执行initrd.target所有单元,包括挂载/etc/fstab
    从initramfs根文件系统切换到磁盘根目录
    systemd执行默认target配置,配置文件/etc/systemd/system/default.target
    systemd执行sysinit.target初始化系统及basic.target准备操作系统
    systemd启动multi-user.target下的本机与服务器服务
    systemd执行multi-user.target下的/etc/rc.d/rc.local
    Systemd执行multi-user.target下的getty.target及登录服务
    systemd执行graphical需要的服务

6、编写Nginx的systemd配置文件, 实现nginx进程开机启动

vim /etc/systemd/system/nginx.service

[Unit]  
Description=nginx                                                                 
After=network.target                                                                    
Documentation=man:nginx(8)
[Service]
Type=forking
ExecStart=/usr/local/nginx1.8.1/sbin/nginx
ExecReload=/usr/local/nginx1.8.1/sbin/nginx -s reload
ExecStop=/usr/local/nginx1.8.1/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

posted @ 2019-08-12 22:25  李卓航  阅读(177)  评论(0编辑  收藏  举报