SHELL训练营--day19_shell练习36-40

#一个 数字的行
#!/bin/bash
while read line
do
    n=`echo $line |sed 's/[^0-9]//g'|wc -L`
    if [ $n -eq 1 ]
    then
        echo $line
    fi
done < 1.txt

#日志切割归档
#!/bin/bash
cd /data/logs
log=1.log
mv_log()
{
    [ -f $1 ] && mv $1 $2
}

[ -f $log.5 ] && rm -f $log.5

for i in `seq 4 -1 1`
do 
    j=$[$i+1]
    mv_log $log.$i $log.$j
done
mv_log $log $log.1

#查找在线IP
#!/bin/bash

for i in `seq 1 254`
do
    if ping -c 2 -W 2 192.168.0.$i &>/dev/null
    then
        echo "192.168.0.$i 在线。"
    else
        echo "192.168.0.$i 不在线。"
    fi
done

#检查脚本错误
#!/bin/bash
sh -n $1 2> /tmp/sh.err
if [ $? -ne 0 ]
then
    cat /tmp/sh.err
    read -p "请输入 q/Q 退出脚本。" c
    if [ -z "$c" ]
    then
        vim $1
        exit 0
    fi

    if [ $c == "q" ] || [ $c == "Q" ]
    then
        exit 0
    else
        vim $1
    fi
else
    echo "脚本 $1 没有语法错误。"
fi

#格式化数字
#!/bin/bash
n=`echo$1|wc -L`
for d in `echo $1|sed 's/./& /g'`
do 
    n2=$[$n%3]
    if [ $n2 -eq 0 ]
    then
        echo -n " ,$d"
    else
        echo  -n  "$d"
    fi
    n=$[$n-1]
done |sed 's/^,//'
echo

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...