beanshell脚本构造生成随机大小的文件
文件下载地址:链接: 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
beanshell脚本构造生成随机大小的文件的更多相关文章
- linux和window下生成任意大小的文件
在Windows环境下的实现方法 使用fsutil命令,在windows xp和win 7下应该都自带了这个命令.命令的格式是 fsutil file createnew 新文件名 文件大小.例如 ...
- linux生成指定大小的文件(转)
# dd if=/dev/zero of=50M.file bs=1M count=50在当前目录下生成一个50M的文件 虚拟块设备文件更通用的名称是硬盘镜像文件(Hard Disk Image),但 ...
- 【Linux】生成任意大小的文件
有时候,我们需要生成指定大小的随机文件,比如在学习过程中使用的测试文件. 命令: Linux:/qinys # dd if=/dev/zero of=tmp.data bs=500k count=1 ...
- Linux shell 脚本攻略之生成任意大小的文件
摘自:<Linux shell 脚本攻略>
- java生成随机大数据文件
package iie.udps.test; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutput ...
- linux shell 脚本攻略学习10--生成任意大小的文件和文本文件的交集与差集详解
一.生成任意大小的文件(dd命令): 举例: amosli@amosli-pc:~/learn/example$ ; + records in + records out bytes ( MB/s a ...
- Windows下创建指定大小的文件
前言 因为需要测试存储容量,所以需要能生成指定大小的文件. 执行 #语法:fsutil file createnew 路径和文件名 文件大小 fsutil file createnew D:\test ...
- 生成随机验证码,上传图片文件,解析HTML
1.生成随机图片验证码 1.1 页面调用createvalidatecode 生成随机图片验证码方法: <div class="inputLine"><label ...
- dd 生成指定大小文件
d命令可以轻易实现创建指定大小的文件,如 dd if=/dev/zero of=test bs=1M count=1000 会生成一个1000M的test文件,文件内容为全0(因从/dev/zero中 ...
- PHP 生成指定大小随机图片
PHP 生成指定大小随机图片 <?php $image_width = 100; $image_height = 100; $image_str = ''; if (isset($_GET['w ...
随机推荐
- JavaScript类
一.什么是js类 类是创建对象的模板,使用class关键字, 类体在大括号{}中,类体中我们可以写需要的属性.方法成员,其中每个类都包含一个特殊方法constructor().它是类的构造函数,由cl ...
- Xilinx XPM使用说明--XPM_MEMORY_SDPRAM
XPM_MEMORY_SDPRAM 参数化宏:简单的双端口RAM 介绍 此宏用于实例化简单双端口RAM.端口A用于从存储器执行写入操作,端口B可用于从存储器读取. 下面介绍XPM_MEMORY实例的基 ...
- Google Earth Engine——基于新的Landsat SR数据集去云处理
根据GEE官方公告,明年原来的Landsat/LT05/C01/T1_SR和Landsat/LC08/C01/T1_SR数据集将停止更新,并提供了新的地表反射率数据,就是LANDSAT/LT05/C0 ...
- 通过命令上传到GitHub
从零开始命令行上传代码到GitHub 前情概要: 要提交代码到GitHub上,本来想要通过idea上传代码,然后去网上搜索了相关的文章,按照步骤一步一步的操作,结果还是没有弄好,也会出现各种各样的 ...
- Word12 财务部制作本年年度报告office真题
1.根据题目一的要求,打开素材文件,点击[文件]-[另存为],选择[当前文件夹],命名为Word. 2.根据题目二的要求,在[开始]里点击[样式]的右下角,打开样式窗口,勾选[显示预览],选中文字,鼠 ...
- go 程序设计语言 命令行参数
最近打算读一读 go程序设计语言这本书, 读语言类的书是一件十分头疼的事情, 因为读一本书就意味着,看着一堆钳子 锥子工具的图片, 概念背了一大堆,仍然不知道怎么用,还是要通过实践. 还是习惯任务驱动 ...
- c++ 从编译到执行
参考博客 原理分析 结合实例 看别人的博客上拼出答案.不会就先模仿吧. 这个是今日头条面试时候的一个题目,当时别提答的多烂了,感觉一个题目准备深了还是非常耗费时间的.小论文一样.c/c++从编译到执行 ...
- Java——File类
File类 File:代表一个文件或者文件夹 方法 createNewFile() exists() getAbsolutePath() getName() getParent() isDirecto ...
- 题解[HEOI2013]SAO.md
题意 给定一棵树,边有方向.要给点重标号,使得边都由小编号指向大编号,求重标号方案数. \(n\le10^5\) 思路 有关树的计数.套路性考虑树形 DP. 设计状态 \(f_{u}\) 表示 \(u ...
- css节流
众所周知,函数节流(throttle)是 JS 中一个非常常见的优化手段,可以有效避免函数过于频繁的执行. 举个例子:一个保存按钮,为了避免重复提交或者服务器考虑,往往需要对点击行为做一定的限制,比如 ...