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

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

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

[root@centos7 ~]# cut -d : -f ,, /etc/passwd|sort -t : -k  -nr|head -n
nfsnobody::/sbin/nologin

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

[root@centos7 ~]# w -h    #查询连接数
root pts/ 192.168.214.1 : .00s .12s .00s w -h
root pts/ 192.168.214.1 : : .03s .00s less -s
root pts/ 172.16.236.130 : : .02s .02s -bash
[root@centos7 ~]# w -h|tr -s " " #压缩空格方便进一步处理
root pts/ 192.168.214.1 : .00s .12s .00s w -h
root pts/ 192.168.214.1 : : .02s .02s -bash
root pts/ 172.16.236.130 : : .02s .02s -bash
[root@centos7 ~]# w -h|tr -s " "|cut -d " " -f #取出IP地址
192.168.214.1
192.168.214.1
172.16.236.130
[root@centos7 ~]# w -h|tr -s " "|cut -d " " -f |sort #排序
192.168.214.1
192.168.214.1
172.16.236.130
[root@centos7 ~]# w -h|tr -s " "|cut -d " " -f |sort|uniq -c #去重并计数
172.16.236.130
192.168.214.1
[root@centos7 ~]# w -h|tr -s " "|cut -d " " -f |sort|uniq -c|sort -nr #按计数逆序
192.168.214.1
172.16.236.130

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

[root@centos7 scripts]# cat createuser.sh
#!/bin/bash #read -p "please input a username: " USER
USER=$ if [ -z "$USER" ];then
echo "Usage: `basename $0` username"
exit
fi if id $USER &> /dev/null ;then
echo "user: $USER already exists"
exit
else
useradd $USER
echo "user: $USER create success"
id $USER
fi
[root@centos7 scripts]# bash createuser.sh
Usage: createuser.sh username
[root@centos7 scripts]# bash createuser.sh hovin
user: hovin already exists
[root@centos7 scripts]# bash createuser.sh alice
user: alice create success
uid=(alice) gid=(alice) groups=(alice)

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

  在.vimrc中定义,对创建的以.sh结尾的脚本应用,相关代码如下:

[root@centos7 ~]# cat .vimrc
set tabstop=
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == sh
call setline(,"#/bin/bash")
call setline(,"#")
call setline(,"#***************************************************")
call setline(,"Author: hovin")
call setline(,"QQ: 405001597")
call setline(,"Date: ".strftime("%Y-%m-%d"))
call setline(,"FileName: ".expand("%"))
call setline(,"Description: The test script")
call setline(,"Copyright (C): ".strftime("%Y")." ALL rights reserved)
call setline(,"#**************************************************")
call setline(,"")
endif
endfunc
autocmd BufNewFile * normal G

[root@centos7 ~]# vim test.sh   #创建脚本

#/bin/bash

#

#***************************************************

Author:             hovin

QQ:                 405001597

Date:               2019-11-23

FileName:           test.sh

Description:        The test script

Copyright (C):      2019 ALL rights reserved

#**************************************************

第四周作业—N42-虚怀若谷的更多相关文章

  1. 20169212《Linux内核原理与分析》第四周作业

    Linux第四周作业 1. 堆栈知识 首先回顾了下堆栈相关的知识,堆栈机制是高级语言可以运行的一个基础,这一块需要重点掌握.函数发生调用时,如图 call指令:将eip的按顺序执行的下一条指令(因为在 ...

  2. 2019年春季学期第四周作业Compile Summarize

    这个作业属于哪个课程 C语言程序设计一 这个作业要求在哪里 2019春季学期第四周作业 我的课程目标 重新学习有关数组的问题 这个作业在哪个具体方面帮助我实现目标 对于置换有了新的见解 参考文献 中国 ...

  3. 2018-2019-1 20189221《Linux内核原理与分析》第四周作业

    2018-2019-1 20189221<Linux内核原理与分析>第四周作业 教材学习:<庖丁解牛Linux内核分析> 第 3 章 MenuOS的构造 计算机三大法宝:存储程 ...

  4. 20169211《Linux内核原理与分析》第四周作业

    20169211<Linux内核原理与分析>第四周作业内容列表 1.教材第3.5章节知识学习总结: 2.实验楼配套实验二实验报告: 1.<linux内核设计与实现>教材第3.5 ...

  5. 2019-2020-1 20199329《Linux内核原理与分析》第四周作业

    <Linux内核原理与分析>第四周作业 一.上周问题总结: 虚拟机环境缺少部分库文件 书本知识使用不够熟练 二.本周学习内容: 1.实验楼环境使用gdb跟踪调试内核 1.1 在该环境下输入 ...

  6. 2019-2020-1 20199328《Linux内核原理与分析》第四周作业

    <Linux内核原理与分析>第四周作业 步骤一 首先我们指定一个内核并指定内存根文件系统,这里的bzImage是vmLinux经过gzip压缩的内核,"b"表示&quo ...

  7. 2003031121-浦娟-python数据分析第四周作业-第二次作业

    项目 内容 课程班级博客链接 20级数据班(本) 作业链接 Python第四周作业第二次作业 博客名称 2003031121-浦娟-python数据分析第四周作业-matolotlib的应用 要求 每 ...

  8. 1903021121—刘明伟—Java第四周作业—java分支语句学习

    项目 内容 课程班级博客链接 19信计班(本) 作业要求链接 第四周作业 要求 每道题要有题目,代码(使用插入代码,不会插入代码的自己查资料解决,不要直接截图代码!!),截图(只截运行结果). 扩展阅 ...

  9. C语言--第四周作业评分和总结(5班)

    作业链接:https://edu.cnblogs.com/campus/hljkj/CS2017-5/homework/1129 一.评分要求 要求1 完成PTA第四周所有题(20分). 要求2 4道 ...

  10. 普林斯顿算法课第四周作业_8Puzzle

    作业地址:http://coursera.cs.princeton.edu/algs4/assignments/8puzzle.html 作业难点: 1.如何求一个Puzzle的解? 根据作业提示,使 ...

随机推荐

  1. easyui表格适应bootstrap

    .panel1 { overflow: hidden; text-align: left; margin:; border:; -moz-border-radius: 0 0 0 0; -webkit ...

  2. JQuery ajax 滚动底部加载更多

    <%@ Page Language="C#" %> <%@ Import Namespace="System.IO" %> <%@ ...

  3. 测开之路一百零九:bootstrap列表

    bootstrap列表 引入bootstrap标签 原本的效果 水平显示 bootstrap列表 列表组合框 在组合框后面加备注 突出显示 a标签列表 <!DOCTYPE html>< ...

  4. Ultra.Base

    winform 基础类库 https://github.com/ZixiangBoy/Ultra.Base

  5. ELK 学习

    [Udemy] ES 7 and Elastic Stack - part 1 [Udemy] ES 7 and Elastic Stack - part 2 [Udemy] ES 7 and Ela ...

  6. Android.应用软件.常用程序下载地址_20190913

    1. 1.1. 健康友行 微信 官网 https://weixin.qq.com/ 抖音 chrome 百度网盘(账号:osskill)中有 1.2. 支付宝 官网 https://mobile.al ...

  7. idea奇葩问题汇总

    1.用idea在tomcat里运行普通的springMVC项目,用nacos做为配置中心,通过@NacosValue来读取配置中心的值,配置了autoRefreshed = true但是不起作用,读取 ...

  8. Parameter setting for Jemeter Post method

    1. create CSV file note: the first line is parameter name 2. Add Controller Edit >Add >Logic C ...

  9. Java web 加载过程

    1.Web容器初始化过程 2.SpringMVC中web.xml配置 3.认识ServletContextListener 4.认识ContextLoaderListener 5.Dispatcher ...

  10. A + B Problem II(1002)

    Problem Description I have a very simple problem for you. Given two integers A and B, your job is to ...