美文网首页
第四周作业

第四周作业

作者: N45刘莅轩 | 来源:发表于2020-05-09 10:42 被阅读0次

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

cat /etc/passwd|grep "/sbin/nologin"|wc -l
cat /etc/passwd|grep "/sbin/nologin"|cut -d: -f1

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

sort -t ':' -n -k 3 /etc/passwd | tail -1 | cut -d: -f 1,3,7

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

netstat -nt|tr -s ' ' : |cut -d: -f6 |sort|uniq -c|sort -n

四、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息

#!/bin/bash

read -p "请输入用户名:" name

if id $name &> /dev/null;then
    echo "$name 存在"
else
    useradd $name && echo "$name 用户添加成功:$(id $name)"
fi

五、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等

]# vim ~/.vimrc
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
    if expand("%:e")=='sh'
        call setline(1,"#!/bin/bash")
        call setline(2,"#")
        call setline(3,"# author: luther liu")
        call setline(4,"# email: 809879580@qq.com")
        call setline(5,"# version: v0.1.0")
        call setline(6,"# date: ".strftime("%Y-%m-%d"))
        call setline(7,"# description: ")
    endif
endfunc

相关文章

网友评论

      本文标题:第四周作业

      本文链接:https://www.haomeiwen.com/subject/dqmhnhtx.html