Skip to content

Instantly share code, notes, and snippets.

@yiquncode
Created March 10, 2011 07:50
Show Gist options
  • Save yiquncode/863715 to your computer and use it in GitHub Desktop.
Save yiquncode/863715 to your computer and use it in GitHub Desktop.
SHELL面试题
#!/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