作業代碼
手動添加使用者資訊
代碼:
#!/bin/bash
read -p "please input you want to add user's name :" username
read -p "please input you want to add user's uid :" userid
grep "^[[:alpha:]].*:x:$userid:[0-9]*:.*:" /etc/passwd &> /dev/null
exist=$?
while([ $exist = 0 ]);do
read -p "error! you input uid is exist. please input you want to add user's uid again :" userid
grep "^[[:alpha:]].*:x:$userid:[0-9]*:.*:" /etc/passwd &> /dev/null
exist=$?
done
read -p "please input you want to add user's group id:" gid
read -p "please input you want to add user's default shell:" shell
echo "$username:x:$userid:$gid::/home/$username:$shell" >> /etc/passwd
echo "$username:x:$gid:" >> /etc/group
salt=`head -1 /dev/urandom | md5sum | cut -d' ' -f1 |sed 's/\([^[:space:]]\{8\}\).*/\1/g'`
echo "please input you want to add user's passwd:"
passwd=`openssl passwd -1 -salt $salt`
t1=$[ `date '+%s'`/86400 ]
echo "$username:$passwd:$t1:0:99999:7:::" >> /etc/shadow
mkdir /home/$username
chown -r $username:$username /home/$username
cp -r /etc/skel/.bashrc* /home/$username
cp -r /etc/skel/.mozilla /home/$username
chmod 700 /home/$username
2 互動式設定編輯網卡
#!/bin/bash
network='/etc/sysconfig/network-scripts'
read -p "please input your set ethernet : " eth
ls -l $network | grep "ifcfg-eth$eth" >> /dev/null
exists=$?
if [ $exists != 0 ] ;then echo "input wrong eth$eth." && exit 5
fi
if [ $exists = 0 ] ;then
read -p "please input your set bootproto [dhcp /static ]:" boot
if([ "$boot" == "dhcp" ] || [ "$boot" == "dhcp" ]);then
hwaddr=`ifconfig eth$eth | grep "^eth$eth" | awk '{print $5}'`
cat > $network/ifcfg-eth$eth << eof
#advanced devices
device=eth$eth
bootproto=$boot
hwaddr=$hwaddr
onboot=yes
type=ethernet
eof
echo "please wait a monment."
ifdown eth$eth && ifup eth$eth
echo "your set dhcp eth$eth info is :"
ifconfig eth$eth
elif ([ "$boot" == "static" -o "$boot" == "static" ]);then
read -p "input ipaddr:" ipaddr
while ([ -z $ipaddr ]);do
read -p "error! please input ipaddr again:" ipaddr
done
read -p "input mask:" mask
while ([ -z $mask ]);do
read -p "error! please input mask again :" mask
read -p "input gateway:" gw
hwaddr=`ifconfig eth$eth | grep "^eth$eth" | awk '{print $5}'`
cat > $network/ifcfg-eth$eth << !
ipaddr=$ipaddr
mask=$mask
gateway=$gw
!
ifdown eth$eth && ifup eth$eth
echo "your set static eth$eth info is :"
else
echo "your input is wrong string."
fi
fi