linux作业四,linux作业4

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

[root@localhost data]# cat /etc/passwd | grep '\/sbin\/nologin' | wc -l

38

[root@localhost data]# cat /etc/passwd | grep '\/sbin\/nologin' | cut -d: -f1

bin

daemon

adm

lp

mail

operator

games

ftp

nobody

systemd-network

dbus

polkitd

sssd

libstoragemgmt

rpc

colord

gluster

saslauth

abrt

setroubleshoot

rtkit

pulse

chrony

rpcuser

nfsnobody

unbound

tss

usbmuxd

geoclue

radvd

qemu

ntp

gdm

gnome-initial-setup

sshd

avahi

postfix

tcpdump

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

[root@localhost data]# cat /etc/passwd | sort -k3 -nr | head -n1

wangbo:x:1000:1000:wangbo:/home/wangbo:/bin/bash

[root@localhost data]# cat /etc/passwd | sort -k3 -nr | head -n1 | cut -d: -f1

wangbo

[root@localhost data]# cat /etc/passwd | sort -k3 -nr | head -n1 | cut -d: -f3

1000

[root@localhost data]# cat /etc/passwd | sort -k3 -nr | head -n1 | cut -d: -f7

/bin/bash

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

[root@localhost data]# netstat -net | grep '^tcp' | tr -s " " |cut -d" " -f5 | cut -d: -f1 | sort | uniq -c | sort -k1 -nr

3 192.168.80.1

2 192.168.80.10

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

#!/bin/bash

if [ $# -ne 1 ];then

echo "Usage: $0 USERNAME"

exit 1

fi

id $1 >& /dev/null

if [ $? -eq 0 ];then

echo "user $1 is already exist!"

else

useradd $1 >& /dev/null

echo "the user $1 informations is follow!"

id $1

fi

[root@localhost data]# sh -n createuser.sh

[root@localhost data]# sh createuser.sh

Usage: createuser.sh USERNAME

[root@localhost data]# sh createuser.sh testuser

the user testuser informations is follow!

uid=1001(testuser) gid=1001(testuser) groups=1001(testuser)

[root@localhost data]# sh createuser.sh testuser

user testuser is already exist!

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

在root用户的家目录下新建一个隐藏文件.vimrc,配置vim的变量,写入以下内容,新建脚本都会自动生成相应的脚本基础信息。

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: wangbo")

call setline(5,"#QQ: 913520405")

call setline(6,"#Date: ".strftime("%Y-%m-%d"))

call setline(7,"#FileName: ".expand("%"))

call setline(8,"#URL: https://www.jianshu.com/u/28ec0e3dbc64")

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@localhost data]# vim demo.sh

#!/bin/bash

#

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

#Author: wangbo

#QQ: 913520405

#Date: 2019-12-23

#FileName: demo.sh

#URL: https://www.jianshu.com/u/28ec0e3dbc64

#Description: The test script

#Copyright (C): 2019 All rights reserved

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值