zoukankan      html  css  js  c++  java
  • 自我学习笔记04

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

    [root@localhost data]#echo "人员总数: `getent passwd|grep "/sbin/nologin"|cut -d: -f1|wc -l`";getent passwd|grep "/sbin/nologin"|cut -d: -f1
    人员总数: 39
    bin
    daemon
    adm
    lp
    mail
    operator
    ......
    2、查出用户UID最大值的用户名、UID及shell类型
    [root@localhost ~]#getent passwd|sort -t: -k3 -rn|head -1|cut -d: -f1,3,7
    nfsnobody:65534:/sbin/nologin

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

    [root@localhost data]#netstat -net|egrep [0-9]|tr -s " " :|cut -d: -f6|sort |uniq -c|sort -r
          4 192.168.232.129
          2 192.168.232.134
          1 192.168.232.128
          1 192.168.232.1

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

    #!/bin/bash
    #
    #********************************************************************
    #Author:        Ronald-wang
    #Date:          2019-11-19
    #FileName:     createuser.sh
    #URL:           https://www.cnblogs.com/Ronald-wang/
    #Description:      The test script
    #Copyright (C):     2019 All rights reserved
    #********************************************************************
    redStart="e[41;30m"
    greenStart="e[42;30m"
    yelloStart="e[43;30m"
    End="e[0m"
    [ $# -ne 1 ] && { echo -e "${redStart}Usage:`basename $0` Parameter error
    i${End}" ; exit 10; }
    id $1 &> /dev/null && { echo -e "${yelloStart}User $1 is exist${End}"; ex
    it 20; }
    useradd $1 &> /dev/null && { echo -e ${greenStart}$1 is created${End}; id
     $1 ;echo wahaha |passwd --stdin $1 &> /dev/null ; } || { echo " Error " 
    ; exit 30; }

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

    #!/bin/bash
    #
    #********************************************************************
    #Author:        Ronald-wang
    #Date:          2019-11-21
    #FileName:     generatescript.sh
    #URL:           https://www.cnblogs.com/Ronald-wang/
    #Description:      The test script
    #Copyright (C):     2019 All rights reserved
    #********************************************************************
    read -p "Please input Script name(1/6):" Scriptname
    read -p "Please input Author name(2/6):" Author
    read -p "Please input Version(3/6):" Version
    read -p "Please input URL(4/6):" URL
    read -p "Please input Date(5/6):" Date
    read -p "Please input Description(6/6):" Description
    touch ${Scriptname}.sh
    File="${Scriptname}.sh"
    echo "#!/bin/bash" > ${File}
    echo "#" >> ${File}
    echo "#********************************************************************" >> ${File}
    echo "#Author:            "${Author}  >> ${File}
    echo "#Version:           "${Version} >> ${File}
    echo "#URL:               "${URL} >> ${File}
    echo "#Date:              "${Date} >> ${File}
    echo "#Description:       "${Description} >> ${File}                                                   
    echo "#Copyright (C):     2019 All rights reserved" >> ${File}
    echo "#********************************************************************" >> ${File}
    
    vim ${File}
    exit
  • 相关阅读:
    python多进程(二)
    PLSQL配置
    sql语句之左连结
    点击lable标出现下拉搜索框及选择功能
    angularjs前端分页自定义指令pagination
    未经整理的工作中遇到的小问题
    晒一晒工作内容.....呵呵勿喷
    配置chrome支持本地(file协议)ajax请求
    html5+angularjs+bootstrap+springmvc+mybatis模糊查询Deme
    oracle的sql积累..&..decode函数使用
  • 原文地址:https://www.cnblogs.com/Ronald-wang/p/11885650.html
Copyright © 2011-2022 走看看