比较数字大小:
#!/bin/bash
read -p "please input three num:" A B C
[ $A -ge $B ] && MAX=$A || MAX=$B
[ $MAX -ge $C ] && echo " the max sum is $MAX" || echo " the max sum is $C"
~
~
查看文件类型:
#!/bin/bash
read -p "please input one dir " DIR
read -p "please input one object " OBJECT
if [ -e $DIR/$OBJECT ];then
if [ -L $DIR/$OBJECT ];then
echo -e "the $DIR/$OBJECT is \033[31m link \033[0m"
elif [ -d $DIR/$OBJECT ];then
echo -e "the $DIR/$OBJECT is \033[31m directory \033[0m"
elif [ -f $DIR/$OBJECT ];then
echo -e "the $DIR/$OBJECT is \033[31m file \033[0m"
elif [ -b $DIR/$OBJECT ];then
echo -e "the $DIR/$OBJECT is \033[31m block device \033[0m"
elif [ -c $DIR/$OBJECT ];then
echo -e "the $DIR/$OBJECT is \033[31m char \033[0m"
fi
else
echo "teh $DIR/$OBJECT is not exist"
fi
~
~
~
手工创建账号
#!/bin/bash
read -p "please input one user : " ACCOUNT
grep -q $ACCOUNT /etc/passwd && echo "the user $ACCOUNT is exist" && exit
#test current max uid and gid
MAXUID=`cut -f3 -d: /etc/passwd |sort -n|tail -n 2 |head -n 1`
MAXGID=`cut -f4 -d: /etc/passwd |sort -n|tail -n 2 |head -n 1`
#chang /etc/passwd
echo "$ACCOUNT:x:$[$MAXUID+1]:$[$MAXGID+1]::/home/$ACCOUNT:/bin/bash">>/etc/passwd
#chang /etc/shadow
chmod u+w /etc/shadow
echo "$ACCOUNT::::::::" >>/etc/shadow
chmod u-w /etc/shadow
#chang /etc/group
echo "$ACCOUNT:x:$[$MAXGID+1]:$ACCOUNT" >>/etc/group
#create home dir
mkdir /home/$ACCOUNT
cp -a /etc/skel/. /home/$ACCOUNT
chown -R $ACCOUNT:$ACCOUNT /home/$ACCOUNT
chmod 700 /home/$ACCOUNT
#create user mailbox
touch /var/spool/mail/$ACCOUNT
chmod 660 /var/spool/mail/$ACCOUNT
chown $ACCOUNT:mail /var/spool/mail/$ACCOUNT
#chang user passwd
echo "123" |passwd --stdin $ACCOUNT &>/dev/null
对账号验证
id u3
tail /etc/passwd
group
shadow
cd /home/u3
ll -a
cd /var/spool/mail/
ping ip (测试时多设几个ip ifconfig eth0:n ip )
#!/bin/bash
for i in $(seq 1 254);do
ping -c 1 -W 1 192.168.2.$i &>/dev/null && echo "the host 192.168.2.$i is online" ||echo"the host 192.168.2.$i is down"
done
改变网卡
#!/bin/bash
. /etc/sysconfig/network-scirpts/ifcfg-eth0
if [ "$BOOTPROT=dhcp" ];then
sed -i -e 's/decp/static/'/etc/sysconfig/network-scirpts/ifcfg-eth0
sed -i -e '3a\IPADDR=192.168.1.172\nNETMASK=255.255.255.0'/etc/sysconfig/network-scirpts/ifcfg-eth0
拷贝脚本.......................
..............................
...........................
#!/bin/bash
while [ true ];do
read -p "A COMMAND " COMMAND
COMMANDSTRING=`which $COMMAND|tail -1`
COMMANDPATH=${COMMANDSTRING%/*}
COMMANDNAME=${COMMANDSTRING##*/}
/bin/cp -f $COMMANDPATH/$COMMANDNAME /mnt/sysroot$COMMANDPATH
for i in `/usr/bin/ldd $COMMANDSTRING`;do
ifecho $i |grep /lib &>/dev/null; then
LIBSTRING=`echo $i |grep /lib `
LIBNAME=${LIBSTRING##*/}
LIBPATH=${LIBSTRING%/*}
/bin/cp -f $LIBPATH/$LIBNAME /mnt/sysroot$LIBPATH
fi
done
done