|
bash-4.2.29
不知道是不是 bash 版本的原因,因为类似 $var = " var" 的判断都是错误的,要改成 “$var"="var"
不过我的确想不通为什么会在 mysql 和 postgresql 那里 line in $lines 分成了两个
- #lines=$(grep -E "bash|csh|ksh|bin/sh" /etc/passwd)
- #for line in $lines;do echo $line; done
- root:x:0:0:root:/root:/bin/bash
- shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
- mysql:x:27:27:MySQL
- Server:/var/lib/mysql:/bin/bash
- postgres:x:26:26:PostgreSQL
- Server:/var/lib/pgsql:/bin/bash
- haulm:x:1000:1002::/home/haulm:/bin/bash
复制代码- #!/bin/sh
- #作者: KanKer
- #设置第一个普通用户的sudo权限
- gid=500
- lines=$(grep -E "bash|csh|ksh|bin/sh" /etc/passwd)
- for line in $lines;do
- tmpgid=$(echo "$line"|cut -f3 -d ":")
- if [ $tmpgid -ge $gid ];then
- tmpuser=$(echo "$line" |cut -f1 -d ":")
- if [ -n "$tmpuser" ];then
- echo "$tmpuser ALL=NOPASSWD:/bin/mount -t iso9660 -o loop\,ro\,nodev\,exec\,nosuid\,* */Mount-ISO*,/bin/umount */Mount-ISO*,/usr/sbin/pppoe-connect,/usr/sbin/pppoe-start,/usr/sbin/pppoe-status,/usr/sbin/pppoe-stop" >> /etc/sudoers
- fi
- fi
- done
复制代码- #!/bin/sh
- #设置第一个普通用户的sudo权限
- gid=500
- cat /etc/passwd|while read line
- do
- if (echo $line|grep -E "x:[0-9]*"|grep -E "bash|csh|ksh|bin/sh">/dev/null)
- then
- lines=$line
- tmpgid=$(echo "$lines"|cut -f3 -d ":")
- if [ "$tmpgid" -ge "$gid" ]
- then
- tmpuser=$(echo "$lines" |cut -f1 -d ":")
- if [ -n "$tmpuser" ]
- then
- echo "$tmpuser ALL=NOPASSWD:/bin/mount -t iso9660 -o loop\,ro\,nodev\,exec\,nosuid\,* */Mount-ISO*,/bin/umount */Mount-ISO*,/usr/sbin/pppoe-connect,/usr/sbin/pppoe-start,/usr/sbin/pppoe-status,/usr/sbin/pppoe-stop" >> /etc/sudoers
- fi
- fi
- fi
- done
复制代码 |
|