0

cp の進行状況を監視するために、次の bash スクリプトを見つけました。

#!/bin/sh
cp_p()
{
   strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
      | awk '{
        count += $NF
            if (count % 10 == 0) {
               percent = count / total_size * 100
               printf "%3d%% [", percent
               for (i=0;i<=percent;i++)
                  printf "="
               printf ">"
               for (i=percent;i<100;i++)
                  printf " "
               printf "]\r"
            }
         }
         END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}

strace コマンドの「-ewrite」オプションがわかりません。私が見つけた最も近いものは、strace の man ページです。

-e write=set 指定されたセットにリストされたファイル記述子に書き込まれたすべてのデータの完全な 16 進数および ASCII ダンプを実行します。たとえば、ファイル記述子 3 と 5 のすべての出力アクティビティを確認するには、-e write=3,5 を使用します。これは、オプション -e trace=write によって制御される write(2) システム コールの通常のトレースとは無関係であることに注意してください。

ただし、 -ewrite オプションの機能がわかりません。

4

1 に答える 1

4

-ewrite は、「書き込み」システム コールのみがトレースされることを意味します。

-e expr トレースするイベントまたはトレース方法を変更する修飾式。式の形式は次のとおりです。

                     [qualifier=][!]value1[,value2]...

          where qualifier is one of trace,  abbrev,  verbose,
          raw,  signal,  read, or write and value is a quali-
          fier-dependent symbol or number.  The default qual-
          ifier  is trace.  Using an exclamation mark negates
          the set of values.  For example, -eopen means  lit-
          erally -e trace=open which in turn means trace only
          the open system call.  By  contrast,  -etrace=!open
          means  to  trace every system call except open.  In
          addition, the special values all and none have  the
          obvious meanings.

          Note that some shells use the exclamation point for
          history expansion even inside quoted arguments.  If
          so,  you  must  escape the exclamation point with a
          backslash.
于 2010-08-23T13:55:56.930 に答える