2014-09-09shell练习

回复 收藏
写个shell,看看你的Linux系统中是否有自定义用户(普通用户),若是有,一共有几个?
{{{密码回复可见}}}

2014-09-09 10:07 举报
已邀请:
0

jxcia2018

赞同来自:

look
0

jxcia2018

赞同来自:

So Long 发表于 2014-9-9 13:04
#!/bin/bash

/bin/cp /etc/passwd  /chengcheng/haha.txt

顶{:4_91:}
0

李宏伟

赞同来自:

n>=500
0

李宏伟

赞同来自:

grep -rc $n /etc/passwd
0

echo

赞同来自:

不会写  学习一下
0

xufanyunwei

赞同来自:

学习
0

timfeng3535

赞同来自:

asdf
0

branttsai

赞同来自:

grep -c 'home' /etc/passwd
0

Toornix

赞同来自:

[root@NewHost shell]# vim sum_of_custom_user.sh
#!/bin/bash
custom_user_sum=`cat /etc/passwd|awk -F':' '$3>499'|wc -l`
echo "The number of custom user is $custom_user_sum"
0

tytywu

赞同来自:

awk -F ':' '$3 >= 500' /etc/passwd|wc -l
0

菜菜鸟

赞同来自:

awk -F ':' '$3>=500' /etc/passwd |wc -l
0

jonnylin

赞同来自:

学习
0

小毅

赞同来自:

学习
0

小毅

赞同来自:

for n in `awk -F ":" '{print $3}' /etc/passwd`;do [ $n -ge 500 ] && cat /etc/passwd|grep $n|awk -F ":" '{print $1}';done
0

yonself

赞同来自:

shell
0

hsm

赞同来自:

学习
0

17051036506

赞同来自:

#!/bin/bash

count=`awk -F ':' '$3>=500 && $6~"/home.*"' /etc/passwd |wc -l`
if [ $count -eq 0 ]
then
        echo "No normal user."
else
        echo $count
fi
0

wzwyql

赞同来自:

1
0

cj2017

赞同来自:

#!/bin/bash
for i in `awk -F ':' '{if ($3>=500) print $1}' /etc/passwd`
do
echo $i >> 1.txt  //新建文件
done
echo "系统中存在`wc -l ptu.txt |awk '{print $1}'`个普通用户"
0

dongdongchen

赞同来自:

看看
0

学习求生存 - openstack运维工程师

赞同来自:

学习
0

nihao426181

赞同来自:

-
0

kevinjin

赞同来自:

#! /bin/bash
#检测/etc/passwd中是否含有uid>500的用户
n=`awk -F ':' '$3>500 {print $1}' /etc/passwd |wc -l`
if [ -n $n ]
then
    echo "There are $n general users in the system."
fi
0

bonijun

赞同来自:

看看

0

有人喜欢蓝

赞同来自:

哈哈哈哈,快快快

0

ichbinww

赞同来自:

对一下

0

kw是id

赞同来自:

#!/bin/bash
uid=`cat /etc/passwd |awk -F ':' '{print $3}'`
a=0
for i in $uid
do
  if [ $i -ge 500 ]
  then
     usr=`cat /etc/passwd |awk -F ':' '$3>=500 {print $1}'` 
  fi
done
echo $usr
for b in $usr
do
  let a=a+1
done
echo "This is system has $a custom users"

0

qwlp19910807

赞同来自:

看看

0

西瓜糖

赞同来自:

!/bin/bash
Description: This script is to check system if exists other users except root.
Author: Jiazhi Yang
Date: 20/11/2016
Script Name: checkuser.sh

number=`awk -F':' '($3 >=500)' /etc/passwd |wc -l`

if [ $number -ne 0 ]; then        

    echo -e "There are $number non-root users on your system."
else        
    echo -e "There are not general users on your system."
fi

0

nmzhaoliming

赞同来自:

学习

0

Ject1992he - linux学习

赞同来自:

学习

0

sun330

赞同来自:

awk -F ':' '{if($3>=500) print $3}' /etc/passwd |wc -l

0

大雁

赞同来自:

awk -F: '$3>=500' /etc/passwd|wc -l

0

王斌

赞同来自:

for i in `awk -F ':' '{print $3}' /etc/passwd`;do if [ $i -gt 500 ]; then echo $i;fi ; done |wc -l

#! /bin/bash
for i in `awk -F ':' '{print $3}' /etc/passwd`
do
    if [ $i -gt 499 ]
    then
        echo $i
    fi
done

# sh filename.sh |wc -l

0

肖永安

赞同来自:

1

0

杨银根

赞同来自:

#!/bin/bash

sum=0

for duser in `less /etc/passwd|grep '/bin/login'|awk -F':' '{print $3}'`

do

    if [ $duser -ge 500 ]

    then

         sum=$[$sum+1]

    fi

done

echo "user in sum $sum."

0

fy88fy

赞同来自:

学习

0

jiapingbian@sina.com

赞同来自:

学习

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: