1、统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来
cat /etc/passwd | grep /sbin/nologin| awk -F":" '{print $1}'
2、查出用户UID最大值的用户名、UID及shell类型
sort -n -k3 -t’:’ /etc/passwd|tail -1f|cut -d: -f1,3,7
3、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
netstat -tun | grep ESTABLISH |cut -d: -f6 | sort -nr | uniq -c
4、编写脚本 createuser.sh,实现如下功能:使用一个用户名做为参数,如果 指定参数的用户存在,就显示其存在,否则添加之;显示添加的用户的id号等 信息
#!/bin/bash
read -p "Create user :" USERNAME
if id -u $USERNAME; then
echo "${USERNAME} already exists!"
else
useradd ${USERNAME} &&
id ${USERNAME}
fi
5、编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等
原答案:
#!/bin/bash
##################################
#Filename:
#Description:
#Date:`date +%F`
#Author:
#Version:
#####################################
[ $# -gt 1 ]&&echo "arg must be three:the first one is FILENAME,the second one is AUTHOR,the third is VERSION"&&exit 1
[ $# -eq 0 ]&&read -p "please input FILENAME,AUTHOR and VERSION: " FILENAME AUTHOR VERSION
[ $# -eq 1 ]&&FILENAME=$1&&AUTHOR=$2&&VERSION=$3
[ -a "$FILENAME" ]&&echo "$FILENAME is exit"&&exit 101
touch $FILENAME
chmod a+x $FILENAME
cat >> ${FILENAME} << EOF
#!/bin/bash
##################################
#Filename:`basename $FILENAME`
#Description:
#Date:`date +%F`
#Author:$AUTHOR
#Version:$VERSION
#####################################
EOF
vim + $FILENAME
set --
批改:
vim ~/.vimrc
set autoindent
set showmatch
set incsearch
set shiftwidth=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: daichengsen")
call setline(5,"#QQ: 476436440")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#Description: ")
call setline(9,"#Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(10,"#********************************************************************")
call setline(11,"")
endif
endfunc
autocmd BufNewFile * normal G
网友评论