SHELL脚本PPT脚本
在能用的前提上再往好里写
1、判断/var/目录下所有文件的类型
[[email protected] 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、九九乘法表
[[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
echo -e "\033[0;${RANDOM_NUMBER}m${j}x${i}=$[$i*$j]\t\c"
done
echo -e "\033[0m"
done
3、判断网络中的主机状态
[[email protected] 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
4、国际象棋棋盘
用到了背景色
[[email protected] ~]# 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、后续六个字符串:efbaf275cd、4be9c40b8b、44b2395c46、 f8c8873ce0、b902c16c8b、ad865d2f63是通过对随机数变量RANDOM随机 执行命令: echo $RANDOM|md5sum|cut –c1-10 后的结果,请破解这些 字符串对应的RANDOM值
#!/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、打印绿色OK和和红色Failed
[[email protected] ~]# cat rgb.sh
#!/bin/bash
. /etc/rc.d/init.d/functions
action OK true
action Failed false
7、判断当前什么操作系统
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
原文地址:https://blog.51cto.com/14012942/2432980
时间: 2024-09-29 11:13:17