第四周作业

题1
找出shell不是/sbin/nologin的用户,并计算个数

[root@use10 ~]# grep -v '/sbin/nologin' /etc/passwd | cut -d ':' -f 1 | cat -n
     1	root
     2	sync
     3	shutdown
     4	halt
     5	liuzhe
     6	mageia
     7	tom
     8	slackware

题2
找出UID最大的账号,并显示账号名、UID、shell类型

[root@use10 ~]# sort -t ':' -k 3 -nr /etc/passwd | cut -d ':' -f 1,3,7 | head -n 1
slackware:2002:/bin/tcsh

题3
统计正在远程连接主机的IP数量

[root@use10 ~]# w -h | awk '{print $3}' | sort | uniq -c | sort -t ' ' -k 1 -nr
      4 192.168.75.43
      3 192.168.75.1
      1 192.168.75.41

题4
通过脚本创建用户,要求判断用户是否存在再创建

[root@use09 ~]# cat createuser.sh 
#!/bin/bash
read -p "Enter one user name: " UserName
id ${UserName} &> /dev/null
if [ $? -eq 0 ];then
    echo "${UserName} is exsits."
else
    useradd ${UserName} &> /dev/null && id ${UserName}
fi
[root@use09 ~]# bash createuser.sh 
Enter one user name: tom     
uid=1001(tom) gid=1001(tom) groups=1001(tom)
[root@use09 ~]# bash createuser.sh 
Enter one user name: tom  
tom is exsits.

题5
自定义shell脚本开头注释

[root@use09 ~]# cat .vimrc 
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
call setline(1,"\###################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: mage")
call append(line(".")+2, "\# mail: mage@123.com")
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\########################################################")
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
endfunc

效果:

###################################################################
# File Name: a.sh
# Author: mage
# mail: mage@123.com
# Created Time: Sat 09 May 2020 04:26:22 PM CST
########################################################
#!/bin/bash
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

okman312

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值