ランダムテストログジェネレータ[閉じる]

ランダムテストログジェネレータ[閉じる]

ランダムテストログデータを生成するスクリプトを作成する必要があります。

ログデータは「|」(パイプ)で区切る必要があり、合計10,000行、各行は500バイト、各行には次の形式のランダムデータが含まれています。

date|time|pid|status|data|comment

各列の範囲:

date    : 20130101
time    : 09:00:00-11:59:59
pid     : 3000-5000
status  : OK || TEMP || PERM
data    : refer words/sentences used in whichever of the following pages and set them randomly - https://en.wikipedia.org/wiki/Amazon_S3
comment : fill in with "X" to fit one line as 500 bytes.

(例)ランダムテストログデータは次のとおりです。

20120101|09:00:00|4887|TEMP|Amazon S3 (Simple Storage Service) is an online file storage web service offered by Amazon Web Services. Amazon S3 provides storage through web services interfaces (REST, SOAP, and BitTorrent).[1] Amazon launched S3, its first publicly available web service, in the United States in March 2006[2] and in Europe in November 2007.[3]|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
20120101|09:00:00|4418|TEMP|At its inception, Amazon charged end users US$0.15 per gigabyte-month, with additional charges for bandwidth used in sending and receiving data, and a per-request (get or put) charge.[4] On November 1, 2008, pricing moved to tiers where end users storing more than 50 terabytes receive discounted pricing.[5] Amazon says that S3 uses the same scalable storage infrastructure that Amazon.com uses to run its own global e-commerce network.|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
20120101|09:00:01|4124|PERM|Amazon S3 is reported to store more than 2 trillion objects as of April 2013.[7] This is up from 102 billion objects as of March 2010,[8] 64 billion objects in August 2009,[9] 52 billion in March 2009,[10] 29 billion in October 2008,[5] 14 billion in January 2008, and 10 billion in October 2007.[11]|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
20120101|09:00:02|3977|OK|S3 uses include web hosting, image hosting, and storage for backup systems. S3 guarantees 99.9% monthly uptime service-level agreement (SLA),[12] that is, not more than 43 minutes of downtime per month.[13]|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
20120101|09:00:02|4020|OK|Details of S3's design are not made public by Amazon, though it clearly manages data with an object storage architecture. According to Amazon, S3's design aims to provide scalability, high availability, and low latency at commodity costs.|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

ベストアンサー1

これは、データに対する追加の変更を実装するために簡単に拡張できる単純なシェルスクリプトです。

#!/bin/bash

count=0
hash='####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################'

while [ "$count" -lt 10000 ]
do
  case $((RANDOM % 3)) in
        (0) status=OK
                ;;
        (1) status=TEMP
                ;;
        (2) status=PERM
                ;;
  esac

  case $((RANDOM % 4)) in
        (0) data=\
'Amazon S3 (Simple Storage Service) is an online file storage web service offered by Amazon Web Services. Amazon S3 provides storage through web services interfaces (REST, SOAP, and BitTorrent).[1] Amazon launched S3, its first publicly available web service, in the United States in March 2006[2] and in Europe in November 2007.[3]'
                ;;
        (1) data=\
'Amazon S3 is reported to store more than 2 trillion objects as of April 2013.[7] This is up from 102 billion objects as of March 2010,[8] 64 billion objects in August 2009,[9] 52 billion in March 2009,[10] 29 billion in October 2008,[5] 14 billion in January 2008, and 10 billion in October 2007.[11]'
                ;;
        (2) data=\
'S3 uses include web hosting, image hosting, and storage for backup systems. S3 guarantees 99.9% monthly uptime service-level agreement (SLA),[12] that is, not more than 43 minutes of downtime per month.[13]'
                ;;
        (3) data=\
'Details of S3'\''s design are not made public by Amazon, though it clearly manages data with an object storage architecture. According to Amazon, S3'\''s design aims to provide scalability, high availability, and low latency at commodity costs.'
                ;;
  esac

  part=$(
    printf '%s|%s|%d|%s|%s' \
        "20130101" \
        $(printf '%02d:%02d:%02d' $((RANDOM % 3 + 9)) $((RANDOM % 60)) $((RANDOM % 60)) ) \
        $((RANDOM % 2000 + 3000)) \
        "$status" \
        "$data"
    )
  printf '%.500s\n' "$part"'|'"$hash"
  count=$((count + 1))
done

このcount変数を使用すると、10,000回繰り返すことができます。このhash変数は一種のマスクです。最後の文字列を500文字で埋めるために使用されます(値は500個のハッシュマークです)。アイデア:) printf %500s | tr " " "#"

caseループ内の2つの文は、サンプルデータから疑似ランダム文字列を選択します。dataここでそのセクションを展開して、より多くのオプションを見ることができます。

変数割り当ては、最初の5つのフィールド(静的日付文字列、9時から11時59分59秒の間の擬似ランダムタイムスタンプ、擬似ランダムpid、選択状態コード、および選択データ文字列)を結合するためpartに使用されます。printf

次に、printfに関連付けられた文字列を印刷するように要求します。

  • 上記のpart文字列
  • 区切り記号|
  • hashその上の痕跡

...その後、印刷文字列全体を500文字に切ります。.500 型幅指定子

おすすめ記事