SHELL script PPT script

SHELL script PPT script

On the premise can go down to write good

1, the determination / var / directory of all files of type

[root@linux1 scripts]# cat filetype.sh 
#!/bin/bash
for i in $(find /var);do
    if [ -b $i ];then
    echo "$i 是块设备"
    elif [ -c $i ];then
    echo "$i是字符设备"
    elif [ -f $i ];then
    echo "$i 是普通文件"
    elif [ -d $i ];then
        echo "$i 是目录文件"
    elif [ -S $i ];then
        echo "$i 是socket文件"
    elif [ -L $i ];then
        echo "$i 是软链接文件"
    else
        echo "文件不存在"
    fi
done 

2, the multiplication table

[root@linux1 scripts]# cat 9x9.sh 
RED="\033[0;31m"
GREEN="\033[0;32m"
NO_COLOR="\033[0m"
for i in {1..9};do
    RANDOM_NUMBER=$[${RANDOM}%7+31]
    for j in `seq $i`;do
        echo -e "\033[0;${RANDOM_NUMBER}m${j}x${i}=$[$i*$j]\t\c"
    done
    echo -e "\033[0m"
done

1566891190518

3, the host determines the status of the network

[root@linux1 scripts]# cat online.sh 
#!/bin/bash
read -p "请输入网络地址(192.168.0.0):" NETID
net=`echo ${NETID} | cut -d. -f1-2`
for i in {1..254};do
    for j in {1..254};do
    { 
    ping -c2 -W1 ${net}.${i}.${j} &>/dev/null
    [ "$?" = "0" ] && echo "${net}.${i}.${j} is up" >>/tmp/online.txt
    } &
    done
done

CPU-intensive

4, chess board

It uses the background color

[root@linux1 ~]# cat chess.sh 
#!/bin/bash
for i in {1..8};do
    if [ $[${i}%2] -eq 1 ];then
    {
        for j in {1..4};do
            echo -en "\033[0;43m  \033[0m"
            echo -en "\033[0;42m  \033[0m"
        done
    }
    else
    {
        for j in {1..4};do
            echo -en "\033[0;42m  \033[0m"
            echo -en "\033[0;43m  \033[0m"
        done
    }
    fi
    echo
done

1566891489852

5, the subsequent six strings: efbaf275cd, 4be9c40b8b, 44b2395c46, f8c8873ce0, b902c16c8b, ad865d2f63 by performing random random RANDOM number of variables command: echo $ RANDOM | md5sum | result of the cut -c1-10, please break these strings RANDOM value corresponding to

#!/bin/bash
passwd='efbaf275cd 4be9c40b8b 44b2395c46 f8c8873ce0 b902c16c8b ad865d2f63'
for j in $(seq 32767);do
{
    random_passwd=$(echo $j|md5sum|cut -c1-10)
    echo $passwd | grep -q $random_passwd
    if [ "$?" = "0" ];then
        echo  `echo $passwd | grep -o $random_passwd`:$j
    fi
}& 
done

1566892920402

6, print and green and red Failed OK

[root@linux1 ~]# cat rgb.sh 
#!/bin/bash
. /etc/rc.d/init.d/functions
action OK true
action Failed false

1566893038505

7, to determine what the current operating system

if [ -f /etc/redhat-release ]; then
    release="centos"
elif cat /etc/issue | grep -Eqi "debian"; then
    release="debian"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
    release="ubuntu"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
    release="centos"
elif cat /proc/version | grep -Eqi "debian"; then
    release="debian"
elif cat /proc/version | grep -Eqi "ubuntu"; then
    release="ubuntu"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
    release="centos"
fi

Guess you like

Origin blog.51cto.com/14012942/2432980