centos 脚本基础练习1

1,写一个脚本:
判断当前系统上是否有用户的默认shell 为bash;如果有,就显示有多少个这类用户;否则就显示没有这类用户;
[root@localhost mscripts]# cat lx1.sh
#!/bin/bash
grep "bash$" /etc/passwd &> /dev/null
RVALUE=$?
if [ $RVALUE -eq 0 ]; then
N1=grep "bash$" /etc/passwd | wc -l
echo "$N1 users' shell is bash"
else
echo "no such the users."
fi
2, 写一个脚本
判断当前系统上是否有用户的默认shell为bash; 如果有,就显示其中一个的用户名;否则,就显赫没有这类用户;
root@localhost mscripts]# cat lx2.sh
#!/bin/bash
grep "bash$" /etc/passwd &> /dev/null
RVALUE=$?
if [ $RVALUE -eq 0 ]; then
N1=grep "\<bash$" /etc/passwd | wc -l
IUSER=grep "\<bash$" /etc/passwd | tail -1 | cut -d: -f1
echo "$N1 users' shell is bash. $IUSER default shell is bash."
else
echo "no such the users."
fi
3, 写一个脚本
给定一个文件,比如 /etc/inittab
判断这个文件中是否有空白行;如果有,则显示其空白行数;否则,显示没有空白行。
[root@localhost mscripts]# cat lx3.sh
#/bin/bash
grep "^$" /etc/inittab &> /dev/null
RVALUE=$?
if [ $RVALUE -eq 0 ]; then
ILINES=grep "^$" /etc/inittab | wc -l
echo "Total $ILINES."
else
echo "No such the lines."
fi
4,写一个脚本
给定一个用户,判断其UID与GID是否一样;如果一样,就显示用户为“good guy”; 否则,就显示此用户为“bad guy”.
[root@localhost mscripts]# cat lx4.sh
#!/bin/bash
USERNAME=student
IDD=id -u $USERNAME
GDD=id -g $USERNAME
if [ $IDD -eq $GDD ]; then
echo "good guy."
else
echo "bad guy."
fi

转载于:https://blog.51cto.com/ahtao/2045174

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值