SHELL Script PPT script
Write in it on the premise that it can be used
1, determine the type of all files in the /var/ directory
[[email protected] scripts]# cat filetype.sh
#!/bin/bash
for i in $(find /var);do
if [-b $i ];then
echo "$i is a block device"
elif [-c $i ];then
echo "$i is a character device"
elif [-f $i ];then
echo "$i is a normal file"
elif [-d $i ];then
echo "$i is a directory file"
elif [-S $i ];then
echo "$i is a socket file"
elif [-L $i ];then
echo "$i is a soft link file"< br /> else
echo "File does not exist"
fi
done
2, nine-nine multiplication table
[[email protected] 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< br /> echo -e "\033[0;${RANDOM_NUMBER}m${j}x${i}=$[$i*$j]\t\c"
done
echo -e "\033[0m"
done
3. Determine the status of the host in the network
< pre>[[email Protected] scripts]# cat online.sh
#!/bin/bash
read -p “Please enter the 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
Consumption of CPU
4. Chess board
Background color is used
[[emailprotected] ~]# 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"< br /> done
}
fi
echo
done
5. The following six strings: efbaf275cd, 4be9c40b8b, 44b2395c46, f8c8873ce0, b902c16c8b, ad865d2f63 are executed by randomly executing commands on the random number variable RANDOM: echo $RANDOM|md5sum|cut-the result after c1-10, please crack the RANDOM value corresponding to 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
[[emailprotected] ~]# cat rgb.sh
#!/bin/bash
. /etc/rc.d/init.d/functions
action OK true
action Failed false
7. Determine what operating system is currently
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