文件管理工具和基础脚本实例

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

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

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

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

脚本内容

#!/bin/bash
if id $1 &> /dev/null;then
   echo "The current user already exists"
else
   useradd $1
   echo "The user is new"
   echo $(id $1)
   echo 11 |passwd --stdin $1 &> /dev/null
   echo "passwd is 11"
   passwd -e $1
fi

现象演示

新用户

  已存在用户

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

脚本内容

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:        fengtianchi")                                                         
    call setline(5,"#QQ:            841743581")
    call setline(6,"#Date:          ".strftime("%Y-%m-%d"))
    call setline(7,"#FileName:     ".expand("%"))
    call setline(8,"#URL:           https://www.cnblogs.com/ftc0926/")
    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

现象

原文地址:https://www.cnblogs.com/ftc0926/p/13208954.html