文件下载地址:链接: https://pan.baidu.com/s/1wum8hfBeLMipdtQlqysp8A?pwd=8e7r 提取码: 8e7r

#!/bin/bash -e

# sh filerandomsize.sh /opt/xntest/1MB ftp_file_1M_10090917.txt 1 M 1000

# sh filerandomsize.sh /opt/xntest/100MB ftp_file_100M_10090917.txt 100 M 100

# sh filerandomsize.sh /opt/xntest/1GB ftp_file_1g_10090917.txt 1024 M 10

# sh filerandomsize.sh /opt/xntest/10GB ftp_file_10g_10090917.txt 10240 M 2

out_file_path=$1

out_file_name=$2

file_size=$3

size_unit=$4

file_count=$5

tmp_out_file_name=$out_file_name.tmp

function check_input_param()

{

if [[ "a" == "a"$out_file_name || "a" == "a"$file_size || "a" == "a"$size_unit ]]; then

echo "Error param input !"

echo "Type in like this: $0 [out-file-name] [file-szie] [size-unit]"

echo "param list as follow:"

echo "[out-file-name]: input your output file name, Relative path and absolute path are OK."

echo "[file-size]: The file size of output file, which must be an integer."

echo "[size-unit]: Only support K/M/G. They mean xxxKB/xxxMB/xxxGB."

exit

fi

}

function check_file_size_if_integer()

{

if [ -n "$file_size" -a "$file_size" = "${file_size//[^0-9]/}" ]; then

echo "file_size=$file_size"

else

echo "[file-size] error: The file size of output file, which must be an integer."

exit

fi

}

function check_file_count_if_integer()

{

if [ -n "$file_count" -a "$file_count" = "${file_count//[^0-9]/}" ]; then

echo "file_count=$file_count"

else

echo "[file-count] error: The file count of output file, which must be an integer."

exit

fi

}

function check_size_unit()

{

if [[ "K" != $size_unit && "M" != $size_unit && "G" != $size_unit ]]; then

echo "[size-unit] error: Only support K/M/G. They mean xxxKB/xxxMB/xxxGB."

exit

fi

}

function create_random_file()

{

dd if=/dev/urandom of=$tmp_out_file_name oflag=direct bs=1$size_unit count=$file_size conv=notrunc

mv $tmp_out_file_name $out_file_name

}

check_input_param

check_file_size_if_integer

check_file_count_if_integer

check_size_unit

create_random_file

if ((file_count>1));then

for ((i=1;i<=file_count;i++))

do

#out_file_name="$file_name-multiple-$i.txt"

echo "yes|cp -rf $out_file_name $out_file_path/multiple-$i-$out_file_name"

yes|cp -rf $out_file_name "$out_file_path/multiple-$i-$out_file_name"

done

echo "$file_count files created: $out_file_path"

else

echo "$out_file_path$out_file_name"

yes|cp -rf $out_file_name $out_file_path

echo "1 file created: $out_file_path"

fi

最新文章

  1. UML聚合与组合
  2. CCombox使用
  3. Python连接MySQL数据库
  4. ICP算法使用遇到的问题
  5. iOS 进阶 第十二天(0413)
  6. nade.js(一)进程管理
  7. IP相关常识
  8. HDOJ--ACM-Steps--2.1.3--Cake(GCD,简单数学)
  9. 【LeetCode题解】数组Array
  10. Ionic2 cordova angular2 打包到Android apk环境搭建
  11. CI_SMOKE配置手册
  12. day-5 python协程与I/O编程深入浅出
  13. PageRank之基于C C#的基本实现
  14. ipv4网络无访问权限
  15. 修改CentOS默认yum源为国内yum镜像源
  16. js-canvas(基本用法)
  17. 将本地时间转换成 UTC 时间,0时区时间
  18. spring整合mybatis在使用.properties文件时候遇到的问题
  19. 机器学习是万能的吗?AI落地有哪些先决条件?
  20. POJ 3080 Blue Jeans 后缀数组, 高度数组 难度:1

热门文章

  1. vue - 开发必须知道的 36 个技巧
  2. No.3.1
  3. Pyodide 中实现网络请求的 3 种方法
  4. CAN 接线参考
  5. C++容器map、unordered_map、set、unordered_set的区别
  6. 字符类型(char)
  7. 代码随想录训练营day 5|24.两两交换链表中的节点 19.删除链表的倒数第N个节点 面试题02.07.链表相交 142.环形链表Ⅱ
  8. ABAP学习(35):常用Function
  9. java之路总结
  10. windows下gitlab-ci.yml配置进入某一目录找不到,无权限