1.for循环嵌套
#!/bin/bash
PDIR=/data/test
for ((i=1;i<=365;i++));do
mkdir -p $PDIR/$i
cd $PDIR/$i
for j in file.txt;do
touch $j
echo liujia >$j
done
done
2.for循环计算
#!/bin/bash
PDIR=/data/test
for ((i=1;i<=365;i++));do
mkdir -p $PDIR/$i
cd $PDIR/$i
for j in file.txt;do
touch $j
echo liujia >$j
done
done
[root@VM-0-14-centos ~]# cat sum.sh
#!/bin/bash
sum=0
for i in {1..100};do
let sum+=i
done
echo sum=$sum
for ((sum=0,i=1;i<=100;i++));do
let sum+=i
done
echo sum=$sum
for ((i=1;i<=9;i++));do
for ((j=1;j<=i;j++));do
echo -e "${i}x${j}=$[i*j]"
done
printf "\n"
done
检测服务器宕机脚本
#!/bin/bash
i=1
for ((i=1;i<60;i++))
do
ping -c 2 10.0.14.$i &> /dev/null
if [ $? -ne 0 ]; then
echo 10.0.14.$i is shutdown
fi
done