S16.shell脚本每日一练
shell 脚本 每日
2023-09-14 09:15:22 时间
31.编写脚本,利用变量RANDOM生成10个随机数字,输出这10个数字,并显示其中的最大值和最小值
[root@rocky8 bin]# vim while_random.sh
#
#**********************************************************************************************
#Author: Raymond
#QQ: 88563128
#Date: 2021-10-10
#FileName: while_random.sh
#URL: raymond.blog.csdn.net
#Description: The test script
#Copyright (C): 2021 All rights reserved
#**********************************************************************************************
declare -i a=0
max=0
min=$RANDOM
while [ $a -le 9 ];do
num=$RANDOM
if [ $num -le $max ];then
if [ $num -le $min ];then
min=$num
fi
else
max=$num
fi
let a++
done
echo "the min number is $min,the max number is $max"
[root@rocky8 bin]# bash while_random.sh
the min number is 2405,the max number is 28407
[root@rocky8 bin]# bash while_random.sh
the min number is 748,the max number is 31986
32.后续六个字符串:efbaf275cd、4be9c40b8b、44b2395c46、f8c8873ce0、b902c16c8b、ad865d2f63是通过对随机数变量RANDOM随机执行命令:echo $RANDOM | md5sum | cut -c1-10 后的结果,请破解这些字符串对应的RANDOM值
[root@rocky8 bin]# vim while_md5sum_random.sh
#!/bin/bash
#
#**********************************************************************************************
#Author: Raymond
#QQ: 88563128
#Date: 2021-10-10
#FileName: while_md5sum_random.sh
#URL: raymond.blog.csdn.net
#Description: The test script
#Copyright (C): 2021 All rights reserved
#**********************************************************************************************
cat >test.txt <<EOF
efbaf275cd
4be9c40b8b
44b2395c46
f8c8873ce0
b902c16c8b
ad865d2f63
EOF
cat test.txt | while read CHESS;do
{ while true;do
MD=`echo $RANDOM|md5sum|cut -c1-10`
if [[ "$MD" == "$CHESS" ]];then
echo $RAN
break
else
let RAN++
fi
done }&
wait
done
[root@rocky8 bin]# bash while_md5sum_random.sh
1152
36060
12754
7940
6945
4420
相关文章
- linux shell 脚本攻略学习8---md5校验,sort排序,uniq命令详解
- 如何在Windows下运行linux shell脚本
- linux shell 脚本攻略学习3
- Linux Shell脚本自动化编程实战-shell变量(一)
- Shell中获取脚本的绝对路径$( cd "$( dirname "$0" )" && pwd)
- 19.第六章 Shell脚本编程基础入门 -- shell 脚本语言的基本用法(二)
- shell脚本注释方法
- Shell脚本:while read line无法读取最后一行的问题
- shell脚本之ping
- Shell脚本之TCP端口扫描器
- Shell脚本之WEB网站静态页面更新检查
- S26.shell脚本每日一练
- S25.shell脚本每日一练
- S17.shell脚本每日一练
- S12.shell脚本每日一练
- S8.shell脚本每日一练
- S7.shell脚本每日一练
- S4.shell脚本每日一练