zoukankan      html  css  js  c++  java
  • 第四周作业

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

     

    [root@db01 ~]# grep -v "/sbin/nologin" /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    sync:x:5:0:sync:/sbin:/bin/sync
    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
    halt:x:7:0:halt:/sbin:/sbin/halt
    guest:x:1000:1000:guest:/home/guest:/bin/bash
    mageia:x:1100:1100::/home/linux:/bin/bash
    slackware:x:2002:2019::/home/slackware:/bin/tcsh
    [root@db01 ~]# grep -v "/sbin/nologin" /etc/passwd | wc -l
    7

     

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

     

    [root@csnode01 ~]# sort -n -t: -k3 /etc/passwd |tail -1|cut -d: -f1,3,7
    nfsnobody:65534:/sbin/nologin

     

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

     

    [root@db01 scripts]# netstat -tn|tr -s " " : |cut -d: -f6|sort |uniq -c|sort -nr
    2 192.168.0.230
    1 Foreign
    1

     

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

     

    [root@db01 scripts]# cat createuser.sh
    #/bin/bash
    #
    read -p "Please input your username: " username
    if id $username &> /dev/null;then
    echo "$username exists"
    else
    useradd $username
    echo "Add username finished"
    echo "The $username info:`id $username`"
    fi
    [root@db01 scripts]# bash createuser.sh
    Please input your username: mark
    Add username finished
    The mark info:uid=2004(mark) gid=2004(mark) groups=2004(mark)
    [root@db01 scripts]# bash createuser.sh
    Please input your username: mark
    mark exists

     

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

     这题不会用shell脚本做,抄袭王老师的模板

    [root@db01 ~]# cat .vimrc
    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: mark")
    call setline(5,"#QQ: 88888888")
    call setline(6,"#Date: ".strftime("%Y-%m-%d"))
    call setline(7,"#FileName: ".expand("%"))
    call setline(8,"#URL: http://www.magedu.com")
    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

    [root@db01 ~]# cat abc.sh
    #!/bin/bash
    #
    #********************************************************************
    #Author: mark
    #QQ: 88888888
    #Date: 2019-12-05
    #FileName: abc.sh
    #URL: http://www.magedu.com
    #Description: The test script
    #Copyright (C): 2019 All rights reserved
    #********************************************************************
    date +%F-%H

  • 相关阅读:
    ASP.NET中POST提交数据并跳转页面
    kindeditor编辑器图片水印
    jquery live hover绑定方法
    ASP.NET MVC实现多个按钮提交事件
    Asp.Net时间戳与时间互转
    Django-管理站点重写admin模板
    Pycharm快捷键整理(Mac)
    Python 调用datetime或者time获取时间的时候以及时间转换,最好设置一下时区 否则会出现相差8个小时的情况
    django中使用原生sql
    [django]用日期来查询datetime类型字段
  • 原文地址:https://www.cnblogs.com/mark-dq/p/11888003.html
Copyright © 2011-2022 走看看