一、
#!/bin/bash
#自动添加用户,并使初始密码为用户账户名,且用户登录时强制其更改密码
i=1
while [ $i -le 15 ]
do
if [ $i -le 9 ]
then
useradd user0$i
echo "user0$i" | passwd --stdin user0$i &> /dev/null
chage -d 0 user0$i
else
useradd user$i
echo "user$i" | passwd --stdin user$i &> /dev/null
chage -d 0 user$i
fi
# userdel -r user$i
let i++
done
#!/bin/bash
#检测当前系统任一服务状态,若未启动则启动之。
read -p 'Input a service name: ' ser
service $ser status &> /dev/null
if [ $? -eq 0 ];
then
echo "服务运行中."
# elif [ $? -eq 3 ];
# then service $ser start
else
service $ser start
fi
#!/bin/bash
#输出30至80之间的偶数及统计个数
g=0
for i in {30..80}
do
yu=`expr $i % 2`
if [ $yu -eq 0 ]
then echo -n "$i " && let g++
fi
done
echo
echo "There are $g 偶数 totally."
#!/bin/bash
#阶乘运算
read -p 'Input a number: ' num
cj=1
for (( i=1;i<=$num;i++ ))
do
let cj*=i
done
echo $cj
#!/bin/bash
#生成九九乘法表
for (( i=1;i<=9;i++ ))
do
for (( j=1;j<=i;j++ ))
do
abc=`expr $i \* $j`
echo -n "$j*$i=$abc "
done
echo
done
#!/bin/bash
#备份MySQL日志
dir=/var/lib/mysql
index=$dir/localhost-bin.index
i=`cat $index | wc -l`
i=$(( $i - 1 ))
if [ ! -e /logbackup ]
then mkdir /logbackup
fi
for log in `head -$i $index | awk -F '/' '{print $2}'`
do cp -nv $dir/$log /logbackup
done
#!/bin/bash
#检测192.168.1.0/24网段,并记录不在线的IP地址信息
net=192.168.1.
#for i in 1 2 3 4 5 6 7 8 9 10
#for i in `seq 254`
for i in {a..z}
do
ping -c 3 $net$i &> /dev/null
if
[ $? -eq 0 ]
then
echo "$net$i is online!!!"
else
echo "$net$i is offline!!!"
fi
done
转载于:https://blog.51cto.com/paundudo/1538738