このログファイルを含むスクリプト(unix)をエミュレータとして実行するにはどうすればよいですか? [閉鎖]

このログファイルを含むスクリプト(unix)をエミュレータとして実行するにはどうすればよいですか? [閉鎖]

次のログがあります。

30-12-2022 23:24:32 : URI: p=2&pwr=0&noipcheck
30-12-2022 23:28:43 : URI: p=2&pwr=1110&noipcheck&debug
30-12-2022 23:28:51 : URI: p=2&pwr=0&noipcheck&debug
30-12-2022 23:31:57 : URI: p=2&pwr=2.200000
30-12-2022 23:50:02 : URI: p=2&pwr=0
31-12-2022 06:59:35 : URI: p=2&pwr=3
31-12-2022 07:04:35 : URI: p=2&pwr=0
31-12-2022 10:39:31 : URI: p=2&pwr=2.900000
31-12-2022 10:53:31 : URI: p=2&pwr=1507.900000
31-12-2022 10:53:36 : URI: p=2&pwr=1326.400000
31-12-2022 10:53:41 : URI: p=2&pwr=1410.200000
31-12-2022 10:53:46 : URI: p=2&pwr=2.900000

今、どのようにスクリプトを書くことができますか?

simulate <hostname> <mydate> <starttimestamp> <endtimestamp> <logfilename>

ここで日付はフィルタリングされ<mydate> <starttimestamp> <endtimestamp>、URIはを使用して呼び出される必要があります<hostname>

sleep2行目をあらかじめ読みなければ時差がわかっていて作るのに苦労しています。

simulate https://www.xxxx.at 31-12-2022 10:00:00 10:55:00 log.txt

Unix環境のbashでこれを行う方法は?

その後、呼び出す必要がありますが、ログ時間に応じて、各呼び出し間のhttps://www.xxxx.at?<URI>最後の時間以降に時間遅延があります。<starttimestamp>

鉄:

     now: 
     `curl` "https://www.xxxx.at?p=2&pwr=2.900000"
     `sleep` timedifference [31-12-2022 10:53:31 - 31-12-2022 10:39:31]
     `curl` "https://www.xxxx.at?p=2&pwr=1507.900000"

      ...

     `sleep` timedifference [31-12-2022 10:53:46 - 31-12-2022 10:53:41] 
     `curl` "https://www.xxxx.at?p=2&pwr=2.900000"

ベストアンサー1

これで、awkスクリプト[named]mysim.awkでこれを行うことができます。

    BEGIN { FS="- :" }
        {
        split($1,a,"[: -]")
        secs = mktime(a[3]" "a[2]" "a[1]" "a[4]" "a[5]" "a[6])
        cmd[NR] = a[11]
        t[NR] = a[6] + 60 * (a[5] + 60 * a[4])
        dt[NR] =a[3]" "a[2]" "a[1]" "a[4]" "a[5]" "a[6]
        }
    END {
        split(sdt,b,"[-: ]")
        split(edt,bb,"[-: ]")
        startsecs = mktime(b[3]" "b[2]" "b[1]" "b[4]" "b[5]" "b[6])
        endsecs   = mktime(bb[3]" "bb[2]" "bb[1]" "bb[4]" "bb[5]" "bb[6])
        print sdt"[->"startsecs"] bis "edt"[->"endsecs"]"
        for (c = 1; c <= NR-1; c++)
            {
            if ((mktime(dt[c]) >= startsecs) && (mktime(dt[c]) <= endsecs))
                {
                d = t[c+1] - t[c]
                if (d < 0) d += 86400
                h = d / 3600
                d %= 3600
                m = d / 60
                s = d % 60
                printf "sleep %02d ; %s%s \n",s,"curl \"https://xxxxx.at/sendsms.php?noresponse&noipcheck&nosms&debug&",cmd[c]"\""
                }
            }
        }

LINUXプロンプトでstartdatetimeおよびenddatetime feを呼び出します。

awk -v sdt="31-12-2022 11:00:00" -v edt="31-12-2022 13:00:00" -f mysim.awk mylog.txt

または、次のようにbashスクリプト(名前runsimulate.sh)を介して:

  #!/bin/bash
  # call f.e.  ./runsimulate.sh "02-01-2023 14:00:00" "02-01-2023 14:50:00" <logfilename>
  awk -f mysim.awk -v sdt="$1" -v edt="$2" $3

おすすめ記事