0
本帖最后由 wyatt88 于 2014-9-9 10:54 编辑
#!/bin/bash
count=`awk -F':' '$3>=500' /etc/passwd|wc -l`
if [ $count -eq 0 ]
then
echo "none" > /dev/null
else
echo "have" >/dev/null
echo $count
fi
#!/bin/bash
count=`awk -F':' '$3>=500' /etc/passwd|wc -l`
if [ $count -eq 0 ]
then
echo "none" > /dev/null
else
echo "have" >/dev/null
echo $count
fi
0
USER=awk -F':' '$3>=500 {print $1}' /etc/passwd |wc -l
if [$USER -gt 0]; then
echo "$USER common users"
eles
echo "no common users"
fi
if [$USER -gt 0]; then
echo "$USER common users"
eles
echo "no common users"
fi
0
对哈 思维定式啊 谢啦 铭哥{:5_121:}
wyatt88 发表于 2014-9-9 10:52
#!/bin/bash
count=`awk -F':' '$3>=500' /etc/passwd|wc -l`
if [ $count -eq 0 ]
对哈 思维定式啊 谢啦 铭哥{:5_121:}
0
#!/bin/bash
awk -F ':' '$3>500' /etc/passwd > num.txt
if [ -e num.txt ];then
echo `wc -l num.txt` | awk -F '' '{print $1}'
fi
awk -F ':' '$3>500' /etc/passwd > num.txt
if [ -e num.txt ];then
echo `wc -l num.txt` | awk -F '' '{print $1}'
fi
0
本帖最后由 陈沛 于 2014-9-9 11:54 编辑
#!/bin/bash
# 2014-09-09
# chenpei
# More than 500 user query
num=`awk -F':' '$3>=500 {print $1}' /etc/passwd | wc -l`
if [ $num -gt 0 ]
then
echo "users: $num"
else
echo "No ordinary users."
fi
#!/bin/bash
# 2014-09-09
# chenpei
# More than 500 user query
num=`awk -F':' '$3>=500 {print $1}' /etc/passwd | wc -l`
if [ $num -gt 0 ]
then
echo "users: $num"
else
echo "No ordinary users."
fi
0
#!/bin/bash
/bin/cp /etc/passwd /chengcheng/haha.txt
a=0
for i in `awk -F ':' '$3>=500 {print $3}' /chengcheng/haha.txt`;do
if [ $i -ge 500 ];then
a=$[$a+1]
else
echo "the user's uid greater 500 is not exist"
fi
done
echo "the user's uid greater 500 is exist,it has $a users"
/bin/cp /etc/passwd /chengcheng/haha.txt
a=0
for i in `awk -F ':' '$3>=500 {print $3}' /chengcheng/haha.txt`;do
if [ $i -ge 500 ];then
a=$[$a+1]
else
echo "the user's uid greater 500 is not exist"
fi
done
echo "the user's uid greater 500 is exist,it has $a users"
0
- #!/bin/bash
- ## This script is for count the sum of general users.
- ## Writed by Louis on 2014/09/09 13:05
- num=`awk -F: '$3>=500 {print $1}' /etc/passwd|wc -l`
- if [ $num -eq 0 ]; then
- echo "There is no general user on this system."
- else
- echo "The sum of general users numbers is: $num"
- fi
0
#!/bin/bash
user=`awk -F':' '$3>=500 {print $1}' /etc/passwd |wc -l`
if [ $user -ne 0 ] ;then
echo $user
else
echo "No ordinary users"
fi
user=`awk -F':' '$3>=500 {print $1}' /etc/passwd |wc -l`
if [ $user -ne 0 ] ;then
echo $user
else
echo "No ordinary users"
fi
0
[root@myCentOS practice]# cat homework1.sh
#!/bin/bash
# This is a shell practice for count the number of normal users
# 20140909 by zhuzhu
num=`awk -F ':' '$3 >=500 {print $1}' /etc/passwd | wc -l`
if [ -z $num ]; then
echo "None normal user"
else
echo "Total $num normal users"
fi
[root@myCentOS practice]# bash homework1.sh
Total 1 normal users
#!/bin/bash
# This is a shell practice for count the number of normal users
# 20140909 by zhuzhu
num=`awk -F ':' '$3 >=500 {print $1}' /etc/passwd | wc -l`
if [ -z $num ]; then
echo "None normal user"
else
echo "Total $num normal users"
fi
[root@myCentOS practice]# bash homework1.sh
Total 1 normal users
0
#!/bin/bash
cat /etc/passwd | awk -F ":" '{print $3 }'> temp.user
declare -i n=0;
for i in `cat temp.user`
do
if [ $i -ge 500 ]
then
n=$n+1
fi
done
echo "the count of user is:$n"
cat /etc/passwd | awk -F ":" '{print $3 }'> temp.user
declare -i n=0;
for i in `cat temp.user`
do
if [ $i -ge 500 ]
then
n=$n+1
fi
done
echo "the count of user is:$n"
0
#!/bin/bash
n=`awk -F':' '$3>=500{print $1}' /root/passwd|wc -l`
if [ $n -eq 0 ];then
echo "没有自定义用户"
else
echo $n
fi
n=`awk -F':' '$3>=500{print $1}' /root/passwd|wc -l`
if [ $n -eq 0 ];then
echo "没有自定义用户"
else
echo $n
fi
0
#!/bin/bash
#Writen by yuhui!
count=`awk -F ':' '$3 >= 500' /etc/passwd | wc -l`
person=`awk -F ':' '$3 >= 500' /etc/passwd | awk -F ':' '{print $1}'`
if [ $count -eq 0 ]
then
echo " 没有普通用户!"
else
echo " 有 $count 个普通用户"
echo $person
fi
#Writen by yuhui!
count=`awk -F ':' '$3 >= 500' /etc/passwd | wc -l`
person=`awk -F ':' '$3 >= 500' /etc/passwd | awk -F ':' '{print $1}'`
if [ $count -eq 0 ]
then
echo " 没有普通用户!"
else
echo " 有 $count 个普通用户"
echo $person
fi
0
本帖最后由 第六感 于 2014-9-10 11:57 编辑
#!/bin/bash
#
USERID=`cut -d: -f3 /etc/passwd`
for i in `echo $USERID`;do
if [ $i -gt 500 ];then
let j++
fi
done
echo $j
#!/bin/bash
#
USERID=`cut -d: -f3 /etc/passwd`
for i in `echo $USERID`;do
if [ $i -gt 500 ];then
let j++
fi
done
echo $j
0
#!/bin/bash
a=`awk -F ':' '$3>=500' /etc/passwd|wc -l `
if [ $a -ge 1 ]
then
echo "the system have $a个user-difined"
else
echo "the system have no user-difined"
fi
a=`awk -F ':' '$3>=500' /etc/passwd|wc -l `
if [ $a -ge 1 ]
then
echo "the system have $a个user-difined"
else
echo "the system have no user-difined"
fi
0
#!/bin/bash
n=`awk -F ':' '$3>499' /etc/passwd | wc -l `
if [ $n -gt 0 ]
echo "this server has $n normal user"
else
echo ‘have no normal users’
fi
n=`awk -F ':' '$3>499' /etc/passwd | wc -l `
if [ $n -gt 0 ]
echo "this server has $n normal user"
else
echo ‘have no normal users’
fi
0
编写思路:普通用户的uid号数都大于等于500,/etc/passwd中第三个字段是uid,一次提取出uid然后判断是否大于等于500就可以判断是否存在普通用户,num计数,存在一次递加1,最终就是总的个数。
#! /bin/bash
#查看Linux系统中是否有自定义用户(普通用户),若是有,一共有几个
num=0
for i in `cat /etc/passwd | awk -F ':' '{print $3}'`
do
if [ $i -ge 500 ]
then
num=$[$num+1]
fi
done
if [ $num -gt 0 ]
then
echo "存在普通用户,一共有:"$num
else
echo "不存在普通用户"
fi
#! /bin/bash
#查看Linux系统中是否有自定义用户(普通用户),若是有,一共有几个
num=0
for i in `cat /etc/passwd | awk -F ':' '{print $3}'`
do
if [ $i -ge 500 ]
then
num=$[$num+1]
fi
done
if [ $num -gt 0 ]
then
echo "存在普通用户,一共有:"$num
else
echo "不存在普通用户"
fi
0
#!/bin/bash
user=`cat /etc/passwd|awk -F ':' '$3>499 {print $3}'|wc -l`
echo "There have $user users."
user=`cat /etc/passwd|awk -F ':' '$3>499 {print $3}'|wc -l`
echo "There have $user users."
0
#! /bin/bash
a=`awk -F ':' '$3 >= 500 ' /etc/passwd|awk -F ':' '{print NR}'|xargs|awk '{print NF}' `
if [ $a -eq 0 ] ;then
echo "No ordinary users.";
else
echo "The ordinary users is total $a";
fi
a=`awk -F ':' '$3 >= 500 ' /etc/passwd|awk -F ':' '{print NR}'|xargs|awk '{print NF}' `
if [ $a -eq 0 ] ;then
echo "No ordinary users.";
else
echo "The ordinary users is total $a";
fi
0
1 #!/bin/bash
2 num=0
3
4
5 for i in `cat /etc/passwd |awk -F ':' '{print $3}'`; do
6 if [ $i -ge 500 ] ; then
7 num=$[$num+1]
8 fi
9 done
10 echo $num
1 #!/bin/bash
2 num=0
3
4
5 for i in `cat /etc/passwd |awk -F ':' '{print $3}'`; do
6 if [ $i -ge 500 ] ; then
7 num=$[$num+1]
8 fi
9 done
10 echo $num
0
#!/bin/bash
#this script is statistical the average user in the system
awk -F ':' '{print $3}' /etc/passwd > /tmp/user_id.txt
echo -n "">/tmp/1.txt
for n in `cat /tmp/user_id.txt`;do
if [ $n -ge 500 ]; then
echo $n >> /tmp/1.txt
fi
done
m=`cat /tmp/1.txt | wc -l`
echo "The number of prdinary users:" $m
#this script is statistical the average user in the system
awk -F ':' '{print $3}' /etc/passwd > /tmp/user_id.txt
echo -n "">/tmp/1.txt
for n in `cat /tmp/user_id.txt`;do
if [ $n -ge 500 ]; then
echo $n >> /tmp/1.txt
fi
done
m=`cat /tmp/1.txt | wc -l`
echo "The number of prdinary users:" $m
0
#!/bin/bash
num=`cat /etc/passwd|awk -F ':' '$3>=500'|grep "bash"|wc -l`
echo "you have $num users"
num=`cat /etc/passwd|awk -F ':' '$3>=500'|grep "bash"|wc -l`
echo "you have $num users"
0
#!/bin/bash
#
a=`awk -F: '$3>=500' /etc/passwd|wc -l`
if [ $a -eq 0 ] ;
then echo "No ordinary users."
else
echo "$a ordinary users."
fi
#
a=`awk -F: '$3>=500' /etc/passwd|wc -l`
if [ $a -eq 0 ] ;
then echo "No ordinary users."
else
echo "$a ordinary users."
fi
0
- #!/bin/bash
- a=0
- for I in `cut -d: -f3 /etc/passwd`;do
- if [ $I -ge 500 ] ;then
- let a=$a+1
- fi
- done
- echo "your system created $a users"
0
aa=`cat /etc/passwd | awk -F: '$3>=500 {print $3}' | wc -l`
if [ $aa -eq 0 ];then
echo "You machine don't have common user!"
else
echo "You machine have "$aa" users!"
fi
if [ $aa -eq 0 ];then
echo "You machine don't have common user!"
else
echo "You machine have "$aa" users!"
fi
0
#!/bin/bash
#date 2015/11/10
#wite by cong
usernum=`nl /etc/passwd|awk -F: '$3>=500'|wc -l`
if [ $usernum -gt 0 ];
then
echo "$usernum 个普通用户"
else
echo "没有普通用户"
fi
#date 2015/11/10
#wite by cong
usernum=`nl /etc/passwd|awk -F: '$3>=500'|wc -l`
if [ $usernum -gt 0 ];
then
echo "$usernum 个普通用户"
else
echo "没有普通用户"
fi
0
#! /bin/bash
##看看你的Linux系统中是否有自定义用户(普通用户),若是有,一共有几个
##write by 2015-12-26
a=`awk -F ':' '$3>499 {print $0}' /etc/passwd|wc -l`
if [ $a -gt 0 ]; then
echo "the system have $a user-define user(s),is:"
awk -F ':' '$3>499 {print $0}' /etc/passwd
else
echo "the system have not user-define user(s)"
fi
##看看你的Linux系统中是否有自定义用户(普通用户),若是有,一共有几个
##write by 2015-12-26
a=`awk -F ':' '$3>499 {print $0}' /etc/passwd|wc -l`
if [ $a -gt 0 ]; then
echo "the system have $a user-define user(s),is:"
awk -F ':' '$3>499 {print $0}' /etc/passwd
else
echo "the system have not user-define user(s)"
fi
0
本帖最后由 369666951 于 2015-12-30 14:57 编辑
- #!/bin/bash
- a=`awk -F ':' '$3>=500' /etc/passwd|wc -l`
- if [ $a -ne 0 ]
- then
- echo $a
- else
- echo "no uid>=500"
- fi
0
- #!/bin/bash
- cat /etc/passwd|while read line
- do
- if [ `echo -n $line|awk -F ":" '{print $3}'` -ge 500 ]; then
- echo `echo -n $line|awk -F ":" '{print $1}'`
- fi
- done
0
#!/bin/bash
m=`cat /etc/passwd|wc -l`
for i in `seq 1 $m`
do
n=`sed -n "$i"p /etc/passwd|awk -F ':' '{print $3}'`
if [ "$n" -gt 500 ];then
sum=`expr $sum + 1`
sed -n "$i"p /etc/passwd|awk -F ':' '{print $1}'
fi
done
echo $sum
m=`cat /etc/passwd|wc -l`
for i in `seq 1 $m`
do
n=`sed -n "$i"p /etc/passwd|awk -F ':' '{print $3}'`
if [ "$n" -gt 500 ];then
sum=`expr $sum + 1`
sed -n "$i"p /etc/passwd|awk -F ':' '{print $1}'
fi
done
echo $sum
0
#!/bin/sh
num=0
for i in `cat /etc/passwd |awk -F':' '{print $3}'`
do
if [ $i -ge 500 ];then
num=$[$num + 1]
fi
done
echo $num
num=0
for i in `cat /etc/passwd |awk -F':' '{print $3}'`
do
if [ $i -ge 500 ];then
num=$[$num + 1]
fi
done
echo $num
0
#!/bin/bash
user=`cat /etc/passwd | awk -F ':' '$3>=500' |wc -l`
if [ $user -eq 0 ]
then
echo "没有普通用户"
else
echo "有 $user 个普通用户"
fi
user=`cat /etc/passwd | awk -F ':' '$3>=500' |wc -l`
if [ $user -eq 0 ]
then
echo "没有普通用户"
else
echo "有 $user 个普通用户"
fi
0
本帖最后由 北辰星 于 2016-2-4 15:12 编辑
#!/bin/bash
u=$[`awk -F ':' '{print $6}' /etc/passwd |grep '/home' |wc -l`]
if [ $u -gt 0 ]
then
echo "该系统中含有 $u 个自定义用户"
else
echo "该系统中没有自定义用户"
fi
为什么都喜欢用 uid大于500 这个条件呢,其实直接匹配出有/home这个字符串不就说明了是自定义的用户吗?而且uid大于500就一定是自定义的用户吗?
#!/bin/bash
u=$[`awk -F ':' '{print $6}' /etc/passwd |grep '/home' |wc -l`]
if [ $u -gt 0 ]
then
echo "该系统中含有 $u 个自定义用户"
else
echo "该系统中没有自定义用户"
fi
为什么都喜欢用 uid大于500 这个条件呢,其实直接匹配出有/home这个字符串不就说明了是自定义的用户吗?而且uid大于500就一定是自定义的用户吗?
0
#!/bin/bash
>/tmp/1.txt
for i in $(seq 1 $(sed -n ""p /etc/passwd|wc -l))
do
n=$(sed -n "$i"p /etc/passwd|awk -F ":" '{print $3}')
if [ $n -ge 500 ]
then
echo $n >>/tmp/1.txt
fi
done
echo "user is $(wc -l /tmp/1.txt|awk '{print $1}')"
#!/bin/bash
>/tmp/1.txt
for i in $(seq 1 $(sed -n ""p /etc/passwd|wc -l))
do
n=$(sed -n "$i"p /etc/passwd|awk -F ":" '{print $3}')
if [ $n -ge 500 ]
then
echo $n >>/tmp/1.txt
fi
done
echo "user is $(wc -l /tmp/1.txt|awk '{print $1}')"
0
本帖最后由 zmh0415 于 2016-2-27 20:35 编辑
a=`awk -F':' '$3>=500 {print $3}' /etc/passwd|wc -l`
if [ $a -gt 1 ]
then
echo "had created normal user"
num=$[$a-1]
echo "user numbers is : $num "
else
echo "no user had been created"
fi
a=`awk -F':' '$3>=500 {print $3}' /etc/passwd|wc -l`
if [ $a -gt 1 ]
then
echo "had created normal user"
num=$[$a-1]
echo "user numbers is : $num "
else
echo "no user had been created"
fi
0
#!/bin/bash
sum=`awk -F':' '$3 >= 500' /etc/passwd | wc -l`
uname=`awk -F: '$3 >= 500 {print $1," Uid=",$3}' /etc/passwd`
if [ $sum -eq 0 ];then
echo "The system exist $sum users."
else
echo "The system exist $sum users:"
echo "$uname"
fi
sum=`awk -F':' '$3 >= 500' /etc/passwd | wc -l`
uname=`awk -F: '$3 >= 500 {print $1," Uid=",$3}' /etc/passwd`
if [ $sum -eq 0 ];then
echo "The system exist $sum users."
else
echo "The system exist $sum users:"
echo "$uname"
fi
0
本帖最后由 ayuan124 于 2016-3-23 18:08 编辑
#!/bin/bash
sum=`awk -F ':' '$3>=500' /etc/passwd|wc -l`
if [ $sum -eq 0 ];then
echo "no ordinary user"
else
echo "ordinary user have $sum"
fi
#!/bin/bash
sum=`awk -F ':' '$3>=500' /etc/passwd|wc -l`
if [ $sum -eq 0 ];then
echo "no ordinary user"
else
echo "ordinary user have $sum"
fi
编辑回复