零零碎碎写的脚本(一):一键添加用户脚本

1.自动判断用户是否存在并添加用户和设置密码,并显示当前系统的用户数并列出可以登录的普通用户。

#!/bin/bash
#Author BY sysk
#DATE 2015/08/13

NAME=$1

#判断传递参数是否合格

if [ $# -lt 1 ]; then
echo -e "\033[32m "You should use it such as: ./addusers arg" \033[0m"
exit 6
fi
if id $NAME ; then
echo "$NAME exists."
else
useradd $NAME
echo "$NAME"| passwd --stdin $NAME
echo "ADD $NAME finished."
fi

#去除系统保留帐号

USERS=`cat /etc/passwd |cut -d: -f1 |grep -v 'bin\|daemon\|adm\|lp\|sync\|shutdown\|halt\|mail\|uucp\|operator\|games\|gopher\|ftp\|nobody\|dbus\|usbmuxd\|vcsa\|rtkit\|avahi-autoipd\|abrt\|gdm\|ntp\|apache\|saslauth\|postfix\|pulse\|sshd\|tcpdump\|mysql'`
TOTAL=`echo -e "$USERS" |wc -l`
echo -n "The current number and users of the system is:"
echo -e "\033[32m "$TOTAL" \033[0m"
echo -e "\033[31m $USERS \033[0m"

 

 

2.ping局域网内所有主机在线状态

#!/bin/bash
for I in `seq 1 254`;do
       ping -c 1 -W 1 172.17.1.$I &>/dev/null && echo "172.17.1.$I is up" ||  echo "172.17.1.$I is down"
       done

 

posted @ 2015-08-12 12:02  夨忆′  阅读(233)  评论(0编辑  收藏  举报