用shell脚本写一段循环将随机可以配置长度字符写入文件,这个写入速度(以每秒多少KB为单位)和字符串大小可以配置
时间: 2024-05-24 15:12:40 浏览: 15
#!/bin/bash
# 设置要写入的文件
file="test.txt"
# 设置要写入的字符串大小和写入速度
string_size=1024 # 1KB
write_speed=10 # 10KB/s
# 循环写入字符串
while true; do
# 生成随机字符串
random_string=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $string_size | head -n 1)
# 写入字符串到文件
echo "$random_string" >> $file
# 等待一段时间
sleep_time=$(echo "scale=3; $string_size / $write_speed" | bc)
sleep $sleep_time
done
# 运行脚本后,可以通过Ctrl+C停止循环写入。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)