adduser.sh linux脚本
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin
if [ $(id -u) -eq 0 ]; then
if [ -f "$1" ]; then
cat "$1" | while read username
do
grep "^$username" /etc/passwd
if [ $? -eq 0 ]; then
echo "$username exists!"
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $username)
useradd -m -p $pass $username
[ $? -eq 0 ] && echo "User '$username' has been added to system!" || echo "Failed to add a user!"
fi
done
else
echo "error username config file"
exit 1
fi
else
echo "Only root can add a user to the system"
exit 2
fi
userlist用户名列表文件
test1
test2
......
再调用脚本 ./adduser.sh userlist 即可批量创建用户名与密码相同的用户。
adduser.sh aix 脚本
#!/bin/ksh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin
if [ $(id -u) -eq 0 ]; then
if [ -f "$1" ]; then
cat "$1" | while read username
do
grep "^$username" /etc/passwd
if [ $? -eq 0 ]; then
echo "$username exists!"
else
useradd -m $username;
[ $? -eq 0 ] && echo "User '$username' has been added to system!" || echo "Failed to add a user!"
echo echo $username:$username \| chpasswd | ksh;
pwdadm -c $username;
fi
done
else
echo "error username config file"
exit 1
fi
else
echo "Only root can add a user to the system"
exit 2
fi
阅读(1845) | 评论(0) | 转发(0) |