欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

编造测试数据

程序员文章站 2022-06-10 20:28:15
...
#! /bin/bash
ran_total(){
	x=`echo {2..6}`
	array=($x)
	num=$(($RANDOM%5))
	total=`echo ${array[${num}]}`
	echo ${total}
}
ran_order(){
	x=`echo {$1..$2}`
	array=($x)
        range=$2-$1
	num=$(($RANDOM%$range))
	order=`echo ${array[${num}]}`
	echo ${order}
}
#获取时间
cat login-logs-2021-03-23_13-35-44.csv | grep ",江苏 苏州 中国,koko-client,0,,True,202" | awk '{print $NF}' | sort -r > file_time
cat login-logs-2021-03-23_13-35-44.csv | grep -v ",江苏 苏州 中国,koko-client,0,,True,202" > file_error
n=0
while [ 113 -gt $n ]
do
  ((n++))
  #获取 2020-12-23 前n天的日期
  date=$(date -d"$n day ago 2020-12-23" +%Y-%m-%d)
  #取得*年*月*日是星期几
  day=`date -d $date +%w`
  if [ $day -lt 1 ] ; then
    continue
  fi
  if [ $day -gt 5 ] ; then
    continue
  fi
#  echo $day
#  echo $date
#  echo $line_new $date
#  ran_orderNumber 1 775
  index=1
  total=`ran_total`
  while [ $total -gt 1 ]
  do
    while true
    do
      index_tmp=$(($RANDOM%400))
      if [ $index_tmp -gt $index ] ; then
        index=$index_tmp
        break
      fi
    done
    ((total--))
#    echo index: $index total: $total
    sum_tmp=`cat login-logs-2021-03-23_13-35-44.csv | md5sum | awk '{print $1}'`
    line_new=`echo ${sum_tmp:0:8}-${sum_tmp:8:4}-${sum_tmp:12:4}-${sum_tmp:16:4}-${sum_tmp:20:12},admin,T,112.80.18.250,江苏 苏州 中国,koko-client,0,,True,`
    time=`sed -n "$index p" file_time`
    echo $line_new$date $time
    echo $line_new$date $time >> login-logs-2021-03-23_13-35-44.csv
    if [ $index -eq 399 ] ; then
        break
    fi
  done
  total=`ran_total`
  while [ $total -gt 1 ]
  do
    while true
    do
      index_tmp=$(($RANDOM%775))
      if [ $index_tmp -gt $index ] ; then
        index=$index_tmp
        break
      fi
    done
    ((total--))
#    echo index: $index total: $total
    sum_tmp=`cat login-logs-2021-03-23_13-35-44.csv | md5sum | awk '{print $1}'`
    line_new=`echo ${sum_tmp:0:8}-${sum_tmp:8:4}-${sum_tmp:12:4}-${sum_tmp:16:4}-${sum_tmp:20:12},admin,T,112.80.18.250,江苏 苏州 中国,koko-client,0,,True,`
    time=`sed -n "$index p" file_time`
    echo $line_new$date $time
    echo $line_new$date $time >> login-logs-2021-03-23_13-35-44.csv
    if [ $index -eq 774 ] ; then
        break
    fi
  done
done

 

相关标签: shell