Bashを使用してすべてのログファイルに時間を追加する

Bashを使用してすべてのログファイルに時間を追加する

.logすべてのファイルから時間を抽出し、すべての時間を1つのエンティティに追加したいと思います。マイログファイルは入れ子になったディレクトリに保存されます。

私のログファイルのディレクトリ構造:

|-- temp-system
|   |-- bash
|   |   |-- bash-4.3-branch_update-5.patch
|   |   |-- build.log
|   |   |-- build.sh
|   |   `-- DONE
|   |-- binutils
|   |   |-- build.log
|   |   |-- build.sh
|   |   `-- DONE
|   |-- build-variables
|   |   |-- build.log
|   |   |-- build.sh
|   |   `-- DONE
|   |-- bzip2
|   |   |-- build.log
|   |   |-- build.sh
|   |   `-- DONE
|   |-- check
|   |   |-- build.log
|   |   |-- build.sh
|   |   `-- DONE
|   |-- cloog
|   |   |-- build.log
|   |   |-- build.sh
|   |   `-- DONE
|   |-- gettext
|   |   |-- build.log
|   |   |-- build.sh
|   |   `-- DONE
|-- build-system
|   |-- gcc
|   |   |-- build.log
|   |   |...

私のログファイルの一部:

are/man/man1'
make[2]: Leaving directory `/tmp/panda64/temp-system/texinfo/texinfo-5.2/man'
make[1]: Leaving directory `/tmp/panda64/temp-system/texinfo/texinfo-5.2/man'
make[1]: Entering directory `/tmp/panda64/temp-system/texinfo/texinfo-5.2'
make[2]: Entering directory `/tmp/panda64/temp-system/texinfo/texinfo-5.2'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/tmp/panda64/temp-system/texinfo/texinfo-5.2'
make[1]: Leaving directory `/tmp/panda64/temp-system/texinfo/texinfo-5.2'
/tmp/panda64/temp-system/texinfo

real    1m59.973s
user    1m26.352s
sys     0m11.820s

各ログファイルには、最後の3行とreal。私のログファイルからこれらのすべての内容を抽出して追加し、任意の形式で出力したいと思います。私はこれを使ってこれを達成しようとしましたが、正しい結果が得られませんでした。usersysHH:MM:SScatgrepregex

修正する

ディレクトリを参照するには、次のコードを使用します。

list=(temp-system build-system)
for direcs in ${list[@]}; do
    case $direcs in
        temp-system )
            pushd $direcs
                _list1=(bash binutils build-variables)
                for subdirecs in ${_list1[@]}; do
                    case $subdirecs in
                        * )
                            # execute code to add the time
                            # and later add this with other
                            # time calculated from other directories
                            ;;
                    esac
                done
            popd;;
    esac
done

ベストアンサー1

巨大なスクリプトの代わりに find を使用してファイルを繰り返すことができます。

find /var/log -name *.log -exec ls {} \;

必要に応じて-execのパスと「ls」を置き換えます。

grep時間は次のようにすることができます。

grep "^real\t" time.txt | awk '{ print  $NF }'

しかし、フォーマットする良い解決策が見つかりません。

おすすめ記事