yoobak

导航

关于shell脚本的编写

关于shell脚本的编写

本脚本实现功能如下:

  • 显示出本机的ip地址

  • 如果ip地址中有3这个数字,那么就打印出当前的系统时间

  • 如果ip地址中不含3这个数字,就批量建立用户magedu_00, magedu_01, ... magedu_100并且所有用户同属于magedu组

  • 打印出/etc/passwd这个文件中可以登陆的用户(非/usr/sbin/nologin)

  • yum安装nginx服务,并且启动该服务

#!/bin/bash
if
ifconfig ens33 | sed -rn "2s/[^0-9]+([0-9.]+).*/\1/p" | grep 3 ;
then  echo `date`
else
for i in magedu{1..5}; do
        groupadd magedu
        useradd user$i -G magedu
done
fi
sed -n '/nologin/!p' /etc/passwd  | cut -d: -f1
yum install nginx
systemctl start nginx
systemctl status nginx
echo "ALL finish!"

运行前检查一下语法(bash -n ip.sh)

运行效果如下:

一个脚本的功能就完成了。

posted on 2023-06-11 20:49  TUOP  阅读(19)  评论(0)    收藏  举报