1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将其用户都显示出来
cat /etc/passwd | grep -v "/sbin/nologin" |cut -d: -f1
2、查出用户UID最大值的用户名,UID及shell类型
cat /etc/passwd | sort -t: -k3 -nr |cut -d: -f1,3,7 |head -n1
3、统计当前连接本机的每个远程主机的连接数,并从大到小排序
netstat -tun | tr -s " " : | cut -d: -f 6 | grep -v Foreign | sort -nr |uniq -c | sort -nr
4、编写createuser.sh实现如下功能使用一个用户名作为参数,如果制定参数的用户存在,就显示其存在,否则添加之显示添加用户的id等信息
#!/bin/bash
#
#********************************************************************
#Author: zhangliufeng
#QQ: 474221349
#Date: 2020-07-06
#FileName: user20.sh
#URL: eddyzhang@yunify.com
#Description: The test script
#Copyright (C): 2020 All rights reserved
#********************************************************************
[ $# = 0 ] && echo "Usage: `basename $0` USERNAME " && sleep 2 && read -p "please input a username:" user
id $user &> /dev/null && { [ $? -eq 0 ]; echo "$1 is exist"; exit 2; } || useradd $user
#id $user &> /dev/null && { echo "User $user is exist"; exit 20; }
#useradd $user &> /dev/null
{ echo "$user is created ";echo Zhu88jie | passwd --stdin $user &> /dev/null; } || { echo "Error"; exit 30; }
id $user
echo "$user password is set!"