马哥教育第三周作业

1.创建用户脚本:

#!/bin/bash
#
#********************************************************************
#Author:        zhangxinhua
#QQ:             303525359
#Date:             2020-04-05
#FileName:        createuser.sh
#URL:             http://www.Idonthave.com
#Description:        The test script
#Copyright (C):     2020 All rights reserved
#********************************************************************
read -p "请输入用户名:" NAME
    if  id "$NAME" &> /dev/null  ;then
        echo "The user $NAME exiting "
elif
    [ -z $NAME ] ;then
        echo "输入不要为空!"; echo "请再次执行脚本";exit
else
    useradd $NAME ; echo "123456" | passwd --stdin  $NAME &> /dev/null;id $NAME; passwd -e $NAME &> /dev/null;echo "初始密码已设置,下次登录请修改密码"
fi

2.初始化安装自定义脚本

#!/bin/bash
#
#********************************************************************
#Author:        zhangxinhua
#QQ:             303525359
#Date:             2020-04-05
#FileName:        reset.sh
#URL:             http://www.Idonthave.com
#Description:        The test script
#Copyright (C):     2020 All rights reserved
#*********************************************************************

COLOR="\E[$[RANDOM%7+31];1m"
END="\E[0m"
echo -e "$COLOR"请选择所需要的选项编号
cat <<EOF
1)PS1变量设置
2)安装工具包(tree,man-pages,lrzsz)
3)定义别名
4)设置ip
EOF

read -p "请选择输入1-4;" N
echo -e "$END"
case $N in
1)
    echo 'PS1="\e[1;32m[\e[1;35m \u @ \e[1;36m\h \e[1;35m\W\e[1;32m]\\$ \e[0m"' > /etc/profile.d/env.sh;echo "PS1变量设置完成,退出当前用户重新登陆生效"
    ;;
2)
    yum -y install tree ; yum -y man-pages;yum -y install lrzsz;echo "安装已完成"
    ;;
3)
    echo "alias cdnet='cd /etc/sysconfig/network-scripts'" >> ~/.bashrc;echo "别名已设置成功,退出当前用户重新登陆生效"
    ;;
4)  echo "ip设置待完成!"
esac

猜你喜欢

转载自www.cnblogs.com/xinhua666/p/12640517.html