正しい出力を生成しないMac El Capitan上で以下のbashスクリプトを実行していますが、コマンドラインでこれらのコマンドを実行すると機能します。私はbashスクリプトを作成しようとしているので、特定のエラーコードを生成するログのファイルの親ディレクトリを見つけるたびに、これらのコマンドを実行する必要はありません。ここで コマンドを通していないBashスクリプト
は、ログファイルの編集さ抜粋です。ここ[2016/06/16 18:11:38] [12.34.56.789] [username] [R] D/Data/Shared/Files/ABC Real Estate - Not the bridge Project/Formal Discovery/001 Drafts/
[2016/06/16 18:11:39] [12.34.56.789] [username] [R] D/Data/Shared/Files/ABC Real Estate - Not the bridge Project/Formal Discovery/2016-04-27 Docs from OC (to be processed)/
--
--
[2016/06/17 15:57:20] [12.34.56.789] [username] [R] [Upload] [D/Data/Shared/Files/ABC Real Estate - Not the bridge Project/Formal Discovery/2016-04-27 Docs from OC (to be processed)/12-15-13 IW CCTV Inspect/My Pane/3637/2013.08.14_0922/SnapShots/36_37_MGP_101.4.jpg] [182.27 KB]
[2016/06/17 15:57:26] [12.34.56.789] [username] [R] [Upload] [D/Data/Shared/Files/ABC Real Estate - Not the bridge Project/Formal Discovery/2016-04-27 Docs from OC (to be processed)/12-15-13 IW CCTV Inspect/My Pane/3637/2013.08.14_0922/SnapShots/36_37_MGP_330.2.jpg] [174.96 KB]
[2016/06/17 15:57:26] [12.34.56.789] [username] [R] Number of files considered for upload: 999
[2016/06/17 15:57:26] [12.34.56.789] [username] [R] Number of files uploaded: 135
[2016/06/17 15:57:27] [12.34.56.789] [username] [R] Number of files in sync: 864
[2016/06/17 15:57:27] [12.34.56.789] [username] [R] idevs error: some files could not be transferred (code 23) at main.c(1234) [generator=1.0.19]
[2016/06/17 09:37:08] [12.34.56.789] [username] [R] receiving file list
[2016/06/17 09:37:17] [12.34.56.789] [username] [R] D/Data/Shared/Files/ABC Real Estate - Not the bridge Project/Formal Discovery/2016-04-27 Docs from OC (to be processed)/12-15-13 IW CCTV Inspect/My Pane/3738/
[2016/06/17 09:37:17] [12.34.56.789] [username] [R] D/Data/Shared/Files/ABC Real Estate - Not the bridge Project/Formal Discovery/2016-04-27 Docs from OC (to be processed)/12-15-13 IW CCTV Inspect/My Pane/3738/2013.08.14_0941/
[2016/06/17 09:37:17] [12.34.56.789] [username] [R] D/Data/Shared/Files/ABC Real Estate - Not the bridge Project/Formal Discovery/2016-04-27 Docs from OC (to be processed)/12-15-13 IW CCTV Inspect/My Pane/3738/2013.08.14_0941/Reports/
である私が上でたくさんのことを試してみました、私の現在のスクリプト:
私は走った一連のコマンドをしていた#!/bin/bash
code23() {
egrep 'code\ 23' -C5 $1 | egrep '\[[A-Z]\/.*' | awk -F\] '{print $6}' | tee ${1}_code_error_files.txt
awk -F\/ '{print $1 "/" $2 "/" $3 "/"}' ${1}_code_error_files.txt | sed 's/\[//g' | sed 's/^\s*\[//g' | sort -u | tee ${1}_code23_errors_dirs.txt
}
if [[ -z $1 ]]; then
echo "Usage: $ bash get_errors logfile.txt"
echo "Please use a file containing the IDrive or IBackup command logs."
else
code23
fi
上記の参照先の機能code23()
自分のUIからrtfファイルとしてログをダウンロードしています。 I cat
これらのファイルを1つのファイルにまとめます。 Bashはこれをテキストファイルとして読んでも問題ありません。私はこれらのファイルに次の一連のコマンドを実行し、それは私のコード23エラーが発生している行の親ディレクトリを取得することで所望の出力、持っている:
`egrep 'code\ 23' -C5 error_file.txt egrep '\[[A-Z]\/.*' | awk -F\] '{print $6}' | sort -u > output_file.txt`
# This successfully printed the full file path of the file that caused the error.
`awk -F\/ '{print $1 "/" $2 "/" $3 "/" }' output_file.txt | sort -u`
# This successfully prints the first three directories of the folders that contain errors.
'sed 's/\[//g' output_file.txt
# I edited the output file with vim to clean it up, by removing the spaces in front of each line, and remove the `[` in front of each directory.
を私がやっているものを教えてください間違って次のようにあなたの助けのすべてに
おかげで、私は、コードを編集し、それが今で素晴らしい作品:
#!/bin/bash
code23() {
egrep 'code\ 23' -C5 $1 | egrep '\[[A-Z]\/.*' | awk -F\[ '{print $7}' | sort -u | tee $1_code23_error_files.txt | awk -F\/ '{print $1 "/" $2 "/" $3 "/"}' | sed 's/^\s*\[//g' | sort -u | tee $1_code23_error_dirs.txt
}
if [[ -z "$1" ]]; then
echo "Usage: $ bash get_errors logfile.txt"
echo "Please use a file containing the ABC Company or XYZ Company command logs."
else
code23 "$1"
fi
ありがとうございました!
すべてのバッククックは何ですか?それらはリテラルですか? –
http://stackoverflow.com/help/mcve/ –
サンプルログファイルから予想される出力を追加してください。あなたは最後の 'egrep'と' awk'の行の回りにバックチックをしたくないですか?行の先頭に4つのスペースを入れて、code/data/errMsg/etcとして表示させます。そして、編集に関する 'help'セクションを読んでください。がんばろう。 – shellter