第三周homework

2021/9/14 6:08:21

本文主要是介绍第三周homework,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
       grep -v '/sbin/nologin' /etc/passwd|cut -d: -f1
2、查出用户UID最大值的用户名、UID及shell类型
       sort -t: -n -k3 /etc/passwd | tail -1 | cut -d: -f 1,3,7
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
       netstat -t | grep ':ssh'|tr -s ' '|cut -d ' ' -f5|cut -d: -f1 | uniq -c|sort -rn
4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
      vim disk.sh

       chmod 755 disk.sh
      #!/bin/bash
      #显示当前硬盘分区中空间利用率最大
      #获取磁盘的使用情况后两列
       df -h |awk '{print $5,$6}'|sed -n '2,$p' > diskinfo.info
       temp=0
        for x in `awk -F '%' '{print $1}' diskinfo.info` #以%分割获取第一列
        do
        if [ $x -gt $temp ]; then #如果获取的数字大于临时变>量
        let temp=$x #把数字赋值给临时变量
        fi
        done
         echo "挂载点: `cat diskinfo.info | awk -F ${temp}% '{print $2}'` 磁盘空间利用率最大,利用率为:$temp%"
5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小

vim systeminfo.sh

chmod 755 systeminfo.sh
BEGINCOLOR="\e[1;35m"
ENDCOLOR="\e[0m"
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
echo -e "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 "OSversion 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 "Meminfototol 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"
#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6、20分钟内通关vimtutor(可参考https://yyqing.me/post/2017/2017-02-22-vimtutor-chinese-summary)



这篇关于第三周homework的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程