linux脚本和启动流程

一、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu用户,并自动设置家目录为/www

#!/bin/bash
if [ $# -ne 2 ];then
    echo 本脚本运行接受两个参数,第一个是需要创建的账户名,第二个是账户的家目录。
else
    id $1 &>/dev/null
    if [ $? -eq 0 ];then
        echo 用户$1已存在哦
    else
        useradd  $1 -d $2 && echo 创建成功 || echo 创建失败
    fi  
fi

二、使用expect实现自动登录系统。

1、编写脚本

[root@centos8 ~]#vim auto
#!/usr/bin/expect
set ip [lindex $argv 0]  
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn ssh $user@$ip
expect {
    "yes/no" { send "yes\n";exp_continue }
    "password" { send "$password\n" }
}
interact

2、脚本加执行权限。

[root@centos8 ~]#chmod +x auto

3、执行脚本,可继续交互执行命令。

[root@centos8 ~]#./auto 10.0.0.88 root 123456
spawn ssh [email protected]
[email protected]'s password: 
Last login: Wed Dec 16 14:31:00 2020 from 10.0.0.135
[root@centos88 ~]#ls
anaconda-ks.cfg  httpd-2.4.46.tar.gz  init.bak  init.sh  passwd  yh.sh
[root@centos88 ~]#

三、简述linux操作系统启动流程

  1. UEFi或BIOS初始化,运行POST开机自检

  2. 选择启动设备

  3. 引导装载程序, centos7是grub2,加载装载程序的配置文件:

    /etc/grub.d/

    /etc/default/grub

    /boot/grub2/grub.cfg

  4. 加载initramfs驱动模块

  5. 加载内核选项

  6. 内核初始化,centos7使用systemd代替init

  7. 执行initrd.target所有单元,包括挂载/etc/fstab

  8. 从initramfs根文件系统切换到磁盘根目录

  9. systemd执行默认target配置,配置文件/etc/systemd/system/default.target

  10. systemd执行sysinit.target初始化系统及basic.target准备操作系统

  11. systemd启动multi-user.target下的本机与服务器服务

  12. systemd执行multi-user.target下的/etc/rc.d/rc.local

  13. Systemd执行multi-user.target下的getty.target及登录服务

  14. systemd执行graphical需要的服务

四、破解centos7 密码。

1、启动时任意键暂停启动,按e键进入编辑模式。

linux脚本和启动流程
2、将光标移动linux 开始的行,添加内核参数rd.break,然后按ctrl-x启动。
linux脚本和启动流程
3、输入以下内容,按照提示输入新密码。


mount –o remount,rw /sysroot
chroot /sysroot
passwd root

​ 4、如果SELinux是启用的,才需要执行下面操作,如查没有启动,不需要执行

touch /.autorelabel

​ 5、退出重启就完成了重置密码操作。

exit
reboot

linux脚本和启动流程

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章