第三周作业

1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来

[root@Centos8 ~]# grep -v "/sbin/nologin" /etc/passwd |cut -d: -f1
root
sync
shutdown
halt
wang
mageia
slackware
slakware
user1
user2
user3
[root@Centos8 ~]# grep -v "/sbin/nologin" /etc/passwd |cut -d: -f 1
root
sync
shutdown
halt
wang
mageia
slackware
slakware
user1
user2
user3
[root@Centos8 ~]# grep -v "/sbin/nologin" /etc/passwd |wc -l
11
​

2、查出用户UID最大值的用户名、UID及shell类型

[root@Centos8 ~]# cat /etc/passwd |cut -d: -f1,3,7 |sort -t: -k2 -n |tail -n1
nobody:65534:/sbin/nologin

3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序

[root@Centos8 ~]# netstat -atunl | grep "ESTABLISHED" | tr -s  " " |cut -d " " -f1,5 | sort -nr
udp 10.0.0.190:67
tcp 10.0.0.1:64809
​

4、编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值

[root@Centos8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          969944       0    969944   0% /dev
tmpfs             998404       0    998404   0% /dev/shm
tmpfs             998404    9652    988752   1% /run
tmpfs             998404       0    998404   0% /sys/fs/cgroup
/dev/sda1      104806400 5610576  99195824   6% /
/dev/sda2       52403200  398408  52004792   1% /data
/dev/sda5         999320  194092    736416  21% /boot
tmpfs             199680      32    199648   1% /run/user/0
[root@Centos8 ~]# bash disk.sh
挂载点:
 /boot磁盘空间利用率最大,利用率为:21%
[root@Centos8 ~]# 
#!/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%"
​
​

5、编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小

[root@Centos8 ~]# bash sysminfo.sh 
My hostname is $Centos8.5
​
IP address is 10.0.0.150
​
OS version is CentOS Linux release 8.5.2111
​
Kernel version is 4.18.0-348.el8.x86_64
​
CPU type is  Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
 Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
​
Memtotol is 1996812 kB
​
Disk space is 200G
​
​
#!/bin/bin
  
echo -e "My hostname is $`hostname`"
echo
echo -e "IP address is `ifconfig ens33 |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`"
echo
echo -e "OS version is `cat /etc/redhat-release`"
​
echo
echo -e "Kernel version is `uname -r`"
echo
echo -e "CPU type is `lscpu|grep "Model name" |cut -d: -f2 |tr -s " "`"
printf "\n"
echo -e "Memtotol is `cat /proc/meminfo |head -n1 |grep -Eo '[0-9]+.*'`"
echo
echo -e "Disk space is `lsblk |grep 'sda\>'|grep -Eo '[0-9]+[[:upper:]]'`"
~                                                                                 
~            

6、20分钟内通关vimtutor(可参考vim中文手册 vimtutor中文版

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值