week04

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了week04相关的知识,希望对你有一定的参考价值。

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

[root@centos7 ~]# grep -v  "/sbin/nologin" /etc/passwd |cut -d: -f1
root
sync
shutdown
halt
zjw
mageia
slackware

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

[root@centos7 ~]# getent passwd  `cat /etc/passwd | cut -d: -f3 |sort -nr |head -n1`
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

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

[root@centos7 ~]# netstat -nt |tr -s " " : |cut -d: -f6 |sort |uniq -c|sort -nr|grep -vE "Foreign"
      6 10.0.0.1
      1 10.0.0.5
      1 10.0.0.4
      1 

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

#!/bin/bash
#
#********************************************************************
#Author:        zhangjiwei
#QQ:            1040204242
#Date:          2020-07-05
#FileName:     createuser.sh
#URL:           https://blog.51cto.com/12514160
#Description:      The test script
#Copyright (C):     2020 All rights reserved
#********************************************************************

#自动添加用户
useradd $1 &>/dev/null
if [ $? -ne 0 ];then
    echo -e "33[33m 用户$1已经存在e[0m"
    else
    echo -e "33[33m 用户$1创建成功e[0m"
    echo -e "$1的UID:33[33m`getent passwd 55kai |cut -d: -f3`e[0m"
    echo -e "$1的GID:33[33m`getent passwd 55kai |cut -d: -f4`e[0m"
    echo -e "$1的SELL:33[33m`getent passwd 55kai |cut -d: -f7`e[0m"
fi

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

#vim .vimrc
set ai
set nu
set cul 
set tabstop=4
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:        zhangjiwei") 
    call setline(5,"#QQ:            1040204242") 
    call setline(6,"#Date:          ".strftime("%Y-%m-%d"))                                          
    call setline(7,"#FileName:     ".expand("%"))
    call setline(8,"#URL:           https://blog.51cto.com/12514160")
    call setline(9,"#Description:      The test script") 
    call setline(10,"#Copyright (C):    ".strftime("%Y")." All rights reserved")
    call setline(11,"#********************************************************************") 
    call setline(12,"") 
    endif
endfunc
autocmd BufNewFile * normal G

以上是关于week04的主要内容,如果未能解决你的问题,请参考以下文章

December 04th 2016 Week 50th Sunday

August 04th 2017 Week 31st Friday

July 04th 2017 Week 27th Tuesday

January 23rd, 2018 Week 04th Tuesday

June 04th 2017 Week 23rd Sunday

January 24th, 2018 Week 04th Wednesday