1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin得用户个数,并将用户都显示出来
[root@centos7 ~]# grep -v nologin /etc/passwd | cut -d: -f1 | cat -n
1 root
2 sync
3 shutdown
4 halt
5 www
6 duwenshuo
2、查出用户UID最大值的用户名、UID及shell类型
[root@centos7 ~]# sort -n -k3 -t’:’ /etc/passwd |tail -1|cut -d: -f1,3,7
www:1000:/bin/bash
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
[root@centos7 ~]# netstat -tn|grep ".*:22\>.*"|tr -s " "|tr " " :|cut -d: -f6|sort |uniq -c|sort -nr
1 10.0.0.1
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
[root@centos7 ~]# vim disk.sh
#!/bin/bash
#显示当前硬盘分区中空间利用率最大的值
df -h | awk '{print $5,$6}' | sed -n '2,$p' > disk.txt
temp=0
for x in `awk -F '%' '{print $1}' disk.txt`
do
if [ $x -gt $temp ] ;then
let temp=$x
fi
done
echo "挂载点:`cat disk.txt | awk -F ${temp}% '{print $2}'`磁盘空间利用率最大,利用率为:$temp%"
[root@centos7 ~]# bash disk.sh
挂载点:
/boot磁盘空间利用率最大,利用率为:62%
5、编写脚本systeminfo.sh,显示当前主机信息,包括:主机名,IPV4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
[root@centos7 ~]# vim systeminfo.sh
[root@centos7 ~]# cat systeminfo.sh
!/bin/bash
#显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
BEGINCOLOR="\e[1;35m"
ENDCOLOR="\e[0m"
echo -e "My hostname is ${BEGINCOLOR}`hostname`$ENDCOLOR"
echo -e "IP address is ${BEGINCOLOR}`ifconfig ens33 |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`$ENDCOLOR"
echo -e "OS version is ${BEGINCOLOR}`cat /etc/redhat-release`$ENDCOLOR"
echo -e "Kernel version is ${BEGINCOLOR}`uname -r`$ENDCOLOR"
echo -e "CPU type is ${BEGINCOLOR}`lscpu|grep "Model name" |cut -d: -f2 |tr -s " "`$ENDCOLOR"
echo -e "Memtotol is ${BEGINCOLOR}`cat /proc/meminfo |head -n1 |grep -Eo '[0-9]+.*'`$ENDCOLOR"
echo -e "Disk space is ${BEGINCOLOR}`lsblk |grep 'sda\>'|grep -Eo '[0-9]+[[:upper:]]'`$ENDCOLOR"
[root@centos7 ~]# bash systeminfo.sh
systeminfo.sh: line 1: !/bin/bash: No such file or directory
My hostname is centos7.6
ens33: error fetching interface information: Device not found
IP address is
OS version is CentOS Linux release 7.5.1804 (Core)
Kernel version is 3.10.0-862.el7.x86_64
CPU type is Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz
Memtotol is 1865308 kB
Disk space is 30G