1洒疚、統(tǒng)計(jì)出/etc/passwd文件中其默認(rèn)shell為非/sbin/nologin的用戶個(gè)數(shù)铝耻,并將其用戶都顯示出來
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憔古、統(tǒng)計(jì)當(dāng)前連接本機(jī)的每個(gè)遠(yuǎn)程主機(jī)的連接數(shù)暑始,并從大到小排序
netstat -tun | tr -s " " : | cut -d: -f 6 | grep -v Foreign | sort -nr |uniq -c | sort -nr
4廓握、編寫createuser.sh實(shí)現(xiàn)如下功能使用一個(gè)用戶名作為參數(shù)搅窿,如果制定參數(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!"