作业代码
手动添加用户信息
代码:
#!/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
done
read -p "input GATEWAY:" GW
HWADDR=`ifconfig eth$ETH | grep "^eth$ETH" | awk '{print $5}'`
cat > $NETWORK/ifcfg-eth$ETH << !
#Advanced Devices
DEVICE=eth$ETH
BOOTPROTO=$BOOT
ONBOOT=yes
TYPE=Ethernet
IPADDR=$IPADDR
HWADDR=$HWADDR
MASK=$MASK
GATEWAY=$GW
!
ifdown eth$ETH && ifup eth$ETH
echo "Your set static eth$ETH info is :"
ifconfig eth$ETH
else
echo "your input is wrong string."
fi
fi