Created
March 10, 2011 07:50
-
-
Save yiquncode/863715 to your computer and use it in GitHub Desktop.
SHELL面试题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#group add | |
for x in 'awk '{print $2}' user.list | sed 's/,/\n/g' | sort | uniq -c|sed 's/[^a-zA-Z]//g'' | |
do | |
groupadd $x &> /dev/null | |
done | |
#back message | |
if (($?==0)) | |
then | |
echo "Group Ok!!" | |
else | |
exit 1 | |
fi | |
#user add | |
for i in 'awk '{print $1}' user.list' | |
do | |
for y in 'awk '{print $2}' password.list' | |
do | |
useradd $i &> /dev/null | |
echo $y | passwd --stdin $i &> /dev/null | |
done | |
done | |
#back message | |
if (($?==0)) | |
then | |
echo "User Ok!" | |
else | |
exit 1 | |
fi | |
#add users to groups | |
for ((q=1;q<=3;q++)) | |
do | |
usermod -G 'awk "NR==$q {print $2}" user.list | awk '{print $2}'' 'awk "NR==$q {print $1}" user.list | awk '{print $1}'' &> /dev/null | |
done | |
if (($?==0)) | |
then | |
echo "All Finished!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment