第十周、shell脚本进阶及系统启动

1、编写脚本,接受二个位置参数,magedu和/www,判断系统是否有magedu,如果没有则自动创建magedu用户,并自动设置家目录为/www
if [ ! $# -eq 2 ];then
	echo "you need to input two arguments: user directory"
else
	if id $1 &> /dev/null;then
		echo user is exist
	else
		useradd -d $2 $1 &>/dev/null
		echo user:$1 created
	fi
fi

2、使用expect实现自动登录系统
ip=$1
user=$2                                                                                                            
password=a!111111
expect <<EOF
set timeout 20
spawn ssh $user@$ip
expect {
        "yes/no" { send "yes\n";exp_continue }
        "password" { send "$password\n" }
}
expect eof
EOF
~             
3、简述linux操作系统启动流程

POST --> MBR --> grub --> Kernel(ramdisk)–>设定默认运行级别(/etc/inittab, /etc/init/*.conf) --> 系统初始化脚本rc.sysinit (/etc/rc.d/rc.sysinit)–> 关闭或启动对应级别的服务(/etc/rc.d/rc*.d/) --> 启动终端

4、破解centos7 密码

方法一

启动时任意键暂停启动
按e键进入编辑模式
将光标移动linux16开始的行,后面添加内核参数rd.break
按ctrl-x启动
mount –o remount,rw /sysroot
chroot /sysroot
passwd root
touch /.autorelabel    #逻辑卷才使用
exit
reboot

方法二

启动时任意键暂停启动
按e键进入编辑模式
将光标移动linux16开始的行,后面添加rw init=/sysroot/bin/sh
按ctrl-x启动
chroot /sysroot
passwd root
touch /.autorelabel    #逻辑卷才使用
exit
reboot

猜你喜欢

转载自blog.csdn.net/wauzy/article/details/106799887