第四周

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

1.grep -v "/sbin/nologin" /etc/passwd | cut -d: -f 1

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

sort -t ":" -n -k3 /etc/passwd |tail -1 | cut -d: -f1,3,7

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


1.第一步 基本实现;ss -nt | tr -s " " | cut -d " " -f5 | cut -d ":" -f1 | uniq -c | sort -nr

2.第二步:过滤掉表头解决方案

ss -nt | grep [[:digit:]] | tr -s " " | cut -d " " -f5 | cut -d ":" -f1 | uniq -c | sort -nr


netstat -nt | grep [[:digit:]] | tr -s " " | cut -d " " -f5 | cut -d ":" -f1 | uniq -c | sort -nr

4、编写脚本

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

#!/bin/bash

if [ $# -eq 0 ];then

    echo "user a argument after the script name"

    exit

elif [ $# -gt 1 ];then

    echo " one arg is requed ,but $# arg was suplled"

    exit

fi

if id -u $1 &> /dev/null;then

    echo "the user has exits,peng refirm it"

else

    useradd $1 && echo "user $1 is created,`id $1`"

fi



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

=====================================================================

set tabstop=4

set softtabstop=4

set shiftwidth=4

set expandtab

set ignorecase

set cursorline

set autoindent

autocmd BufNewFile *.sh exec ":call SetTitle()"

func SetTitle()

if expand("%:e") == 'sh'

call setline(1,"#!/bin/bash")

call setline(2,"#")

call setline(3,"#***********************************************")

    call setline(4,"#Author                  czq")

    call setline(5,"#phone                  177**********")

    cal  setline(6,"#Date                  ".strftime("%Y-%m-%d"))

    endif

endfunc

autocmd BufNewFile * normal G

===================================================================================

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。