SHELL script PPT script

Keywords: Linux CentOS Ubuntu network Red Hat

Write on the premise that you can use it

1. Determine the type of all files in / var / directory

[root@linux1 scripts]# cat filetype.sh 
#!/bin/bash
for i in $(find /var);do
    if [ -b $i ];then
    echo "$i It's a block device."
    elif [ -c $i ];then
    echo "$i It's a character device."
    elif [ -f $i ];then
    echo "$i It's an ordinary document."
    elif [ -d $i ];then
        echo "$i Is a catalog file"
    elif [ -S $i ];then
        echo "$i yes socket file"
    elif [ -L $i ];then
        echo "$i Is a soft link file"
    else
        echo "file does not exist"
    fi
done 

2. Nine-nine multiplication tables

[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

3. Judging Host State in Network

[root@linux1 scripts]# cat online.sh 
#!/bin/bash
read -p "Please enter your network address(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

Consuming CPU

4. Chess Board

Background color is used

[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

5. The following six strings: efbaf275cd, 4be9c40b8b, 44b2395c46, f8c8873ce0, b902c16c8b, ad865d2f63 are the results of random execution of commands on random number variable RANDOM: echo $RANDOM|md5sum|cut-c1-10. Please decipher the corresponding RANDOM values of these strings.

#!/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

6. Print green OK and red Failed

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

7. Determine what operation system is currently in operation.

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

Posted by FatStratCat on Thu, 03 Oct 2019 09:48:53 -0700