teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

8

質問内容の更新

2019/03/05 00:53

投稿

raccoondog
raccoondog

スコア77

title CHANGED
File without changes
body CHANGED
@@ -106,22 +106,27 @@
106
106
 
107
107
 
108
108
  ```
109
- ●実行状況
109
+ 2019/3/5の実行状況
110
110
  ```ここに言語を入力
111
+ ●問題
112
+ プログラム実行時に、プロンプトがかえってこず
113
+ 手動でenterキーを押下しないとプログラム実行が完了しない
114
+
115
+
116
+ ●プログラム
117
+
111
118
  srdcs04% cat log_kanshi.sh
112
119
  #!/bin/bash
113
120
  #--- 変数初期値代入 ------------------------
114
- echo "test_001"
115
121
  export WATCH_FILE="/export/home/srdcs/embulk_test/log/bulkinsert_M_ORG.log"
116
122
  export MAIL_CMD="/usr/sbin/sendmail"
117
123
  export MAIL_TMP_FILE="/export/home/srdcs/embulk_test/mail/mail_tmp_file"
118
124
  export CHECK_LOG="/export/home/srdcs/embulk_test/mail/check.log"
119
125
  export MAIL_LIST="/export/home/srdcs/embulk_test/mail/mail.list"
126
+ export ADDR="xxx@xxxx"
120
127
  export ERROR_CODE_001="Error"
121
128
  export TIME="`date '+%y/%m/%d %H:%M:%S'`"
122
129
 
123
- echo "test_002"
124
-
125
130
  #
126
131
  # メールヘッダ部作成
127
132
  #
@@ -132,39 +137,25 @@
132
137
  echo "=====================" >> ${MAIL_TMP_FILE}
133
138
  echo "Message:" >> ${MAIL_TMP_FILE}
134
139
 
135
- echo "test_003"
136
-
137
140
  while read line
138
141
  do
139
142
  cat ${WATCH_FILE} | grep "${ERROR_CODE_001}"
140
143
  if [ $? = "0" ];then
141
144
  echo "error occurred" >> ${MAIL_TMP_FILE}
142
- echo "test_004"
143
- ${MAIL_CMD} -f embulk_`hostname`@jp.yazaki.com ${MAIL_LIST} < ${MAIL_TMP_FILE}
145
+ ${MAIL_CMD} -f embulk_xxxx@jp.xxxx.com ${ADDR} < ${MAIL_TMP_FILE}
144
146
  exit 1
147
+ break;
145
148
  fi
146
149
  done
147
150
 
148
- echo "test_005"
149
- srdcs04%
151
+ ●実行後送付されるメール
150
- srdcs04% /bin/bash log_kanshi.sh
151
- test_001
152
- test_002
153
- test_003
154
152
 
155
- Error
156
- test_004
157
- srdcs04%
158
-
159
- srdcs04% cat mail_tmp_file
160
153
  =====================
161
154
  DATE : 19/03/04 16:35:49
162
- HOST : srdcs04
155
+ HOST : xxxx
163
156
  =====================
164
157
  Message:
165
158
  error occurred
166
- srdcs04%
159
+ ===========
167
160
 
168
- srdcs04%cat mail.list
169
- xxx.xxx@xxx.com
170
161
  ```

7

質問更新

2019/03/05 00:53

投稿

raccoondog
raccoondog

スコア77

title CHANGED
File without changes
body CHANGED
@@ -105,4 +105,66 @@
105
105
  tail -n 0 --follow=name --retry $TARGET_LOG | hit_action~
106
106
 
107
107
 
108
+ ```
109
+ ●実行状況
110
+ ```ここに言語を入力
111
+ srdcs04% cat log_kanshi.sh
112
+ #!/bin/bash
113
+ #--- 変数初期値代入 ------------------------
114
+ echo "test_001"
115
+ export WATCH_FILE="/export/home/srdcs/embulk_test/log/bulkinsert_M_ORG.log"
116
+ export MAIL_CMD="/usr/sbin/sendmail"
117
+ export MAIL_TMP_FILE="/export/home/srdcs/embulk_test/mail/mail_tmp_file"
118
+ export CHECK_LOG="/export/home/srdcs/embulk_test/mail/check.log"
119
+ export MAIL_LIST="/export/home/srdcs/embulk_test/mail/mail.list"
120
+ export ERROR_CODE_001="Error"
121
+ export TIME="`date '+%y/%m/%d %H:%M:%S'`"
122
+
123
+ echo "test_002"
124
+
125
+ #
126
+ # メールヘッダ部作成
127
+ #
128
+
129
+ echo "=====================" >> ${MAIL_TMP_FILE}
130
+ echo "DATE : ${TIME}" >> ${MAIL_TMP_FILE}
131
+ echo "HOST : `hostname`" >> ${MAIL_TMP_FILE}
132
+ echo "=====================" >> ${MAIL_TMP_FILE}
133
+ echo "Message:" >> ${MAIL_TMP_FILE}
134
+
135
+ echo "test_003"
136
+
137
+ while read line
138
+ do
139
+ cat ${WATCH_FILE} | grep "${ERROR_CODE_001}"
140
+ if [ $? = "0" ];then
141
+ echo "error occurred" >> ${MAIL_TMP_FILE}
142
+ echo "test_004"
143
+ ${MAIL_CMD} -f embulk_`hostname`@jp.yazaki.com ${MAIL_LIST} < ${MAIL_TMP_FILE}
144
+ exit 1
145
+ fi
146
+ done
147
+
148
+ echo "test_005"
149
+ srdcs04%
150
+ srdcs04% /bin/bash log_kanshi.sh
151
+ test_001
152
+ test_002
153
+ test_003
154
+
155
+ Error
156
+ test_004
157
+ srdcs04%
158
+
159
+ srdcs04% cat mail_tmp_file
160
+ =====================
161
+ DATE : 19/03/04 16:35:49
162
+ HOST : srdcs04
163
+ =====================
164
+ Message:
165
+ error occurred
166
+ srdcs04%
167
+
168
+ srdcs04%cat mail.list
169
+ xxx.xxx@xxx.com
108
170
  ```

6

質問内容更新

2019/03/04 07:40

投稿

raccoondog
raccoondog

スコア77

title CHANGED
@@ -1,1 +1,1 @@
1
- cshで監視スクリプト
1
+ solaris 11 bashで監視スクリプト
body CHANGED
@@ -1,8 +1,8 @@
1
- solaris 11のcronを使って、コマンドを実行しています。(csh)
1
+ solaris 11のcronを使って、コマンドを実行しています。
2
2
 
3
3
  cronに登録しているシェルスクリプトAは、単純にコマンド実行のみとなっております。
4
4
 
5
- シェルスクリプトAを改修して、コマンド実行判定をして(echo $status)
5
+ シェルスクリプトAを改修して、コマンド実行判定をして(echo $!)
6
6
  ➀正常な場合には、次のステップでログ監視
7
7
  ➁異常な場合には、メーリングリストへエラー通知
8
8
 
@@ -73,43 +73,36 @@
73
73
 
74
74
  ⇒メール本文内容が文字化けします。。。
75
75
  ```
76
-
77
- ➁についてメーヘッダー
76
+ ログ監視シェスクリプト
78
77
  ```ここに言語を入力
79
- Return-Path: <xxx@xxx.xx.xxx.co.jp>
80
- Delivered-To: xxx@xxx.net
81
- Received: from mas16.kagoya.net
82
- by mas16.kagoya.net with LMTP id eNNjMqKPeFxTGAAAA3Lt0w
83
- for <xxx@xxx.net>; Fri, 01 Mar 2019 10:49:22 +0900
84
- Received: from fmail02.kagoya.net (fmail02.kagoya.net [203.142.195.186])
85
- by mas16.kagoya.net (Postfix) with ESMTP id 65FC640762DF
86
- for <xxx@xxx.net>; Fri, 1 Mar 2019 10:49:20 +0900 (JST)
87
- Received: from dmail03.kagoya.net (dmail03.kagoya.net [210.134.58.253])
88
- by fmail02.kagoya.net with ESMTP id x211nKsV019758-x211nKsW019758
89
- for <xxx@xxx.net>; Fri, 1 Mar 2019 10:49:20 +0900
90
- Received: from esa9.hc3012-19.iphmx.com (esa9.hc3012-19.iphmx.com [139.138.32.61])
91
- by dmail03.kagoya.net (Postfix) with ESMTP id D7B224242862
92
- for <xxx.xxx@xxx.com>; Fri, 1 Mar 2019 10:49:19 +0900 (JST)
93
- Received: from unknown (HELO xxxxxx.jp.xxxxx.com) ([106.186.192.36])
94
- by esa9.hc3012-19.iphmx.com with ESMTP; 01 Mar 2019 10:49:19 +0900
95
- Received: from ykhdc21ws024015.jp.xxxxx.local ([10.194.24.15])
96
- by xxxxxx.jp.xxxxx.com (sendmail) with ESMTP id x211nH9M024973
97
- for <xxx.xxx@xxx.com>; Fri, 1 Mar 2019 10:49:17 +0900
98
- Received: from xxx.xx.xx.co.jp (10.1.31.75) by exchange.jp.xxxxx.com
99
- (10.194.24.15) with Microsoft SMTP Server (TLS) id 14.3.158.1; Fri, 1 Mar
100
- 2019 10:49:17 +0900
101
- Received: from xxx.xx.xx.co.jp (localhost [127.0.0.1]) by
102
- xxx.xx.xx.co.jp (8.14.5+Sun/8.14.5) with ESMTP id x211nG1M022559 for
103
- <xxx.xxx@xxx.com>; Fri, 1 Mar 2019 10:49:16 +0900 (JST)
104
- Received: (from xxxx@localhost) by xxx.xx.xx.co.jp
105
- (8.14.5+Sun/8.14.5/Submit) id x211nGnv022558 for xxx.xxx@xxx.com
106
- Fri, 1 Mar 2019 10:49:16 +0900 (JST)
107
- Date: Fri, 1 Mar 2019 10:49:16 +0900
108
- From: <xxx@xxx.xx.xxx.co.jp>
109
- Message-ID: <201903010149.x211nGnv022558@xxx.xx.xx.co.jp>
110
- MIME-Version: 1.0
78
+ log_kanshi.sh
111
- Content-Type: text/plain; charset="utf-8"
112
- To: Undisclosed recipients:;
113
79
 
114
80
 
81
+ #--- 変数初期値代入 ------------------------
82
+ export WATCH_FILE="/export/home/srdcs/embulk_test/log/bulkinsert_M_ORG.log"
83
+ export MAIL_CMD="/usr/sbin/sendmail"
84
+ export MAIL_TMP_FILE="/export/home/srdcs/embulk_test/mail/mail_tmp_file"
85
+ export CHECK_LOG="/export/home/srdcs/embulk_test/mail/check.log"
86
+ export MAIL_LIST="/export/home/srdcs/embulk_test/mail/mail.list"
87
+ export ERROR_CODE_001="Error"
88
+ export TIME="`date '+%y/%m/%d %H:%M:%S'`"
89
+
90
+ hit_action() {
91
+ while read line
92
+ do
93
+ echo ${WATCH_FILE} | grep -q "${ERROR_CODE_001}"
94
+ if [ $? = "0" ];then
95
+ echo "error occurred" >> ${MAIL_TMP_FILE}
96
+ ${MAIL_CMD} -f embulk_`hostname`@jp.yazaki.com ${ADDR} < ${MAIL_TMP_FILE}
97
+ fi
98
+ done
99
+ }
100
+
101
+ if [ ! -f ${WATCH_FILE} ]; then
102
+ touch ${WATCH_FILE}
103
+ fi
104
+
105
+ tail -n 0 --follow=name --retry $TARGET_LOG | hit_action~
106
+
107
+
115
108
  ```

5

質問更新

2019/03/01 07:59

投稿

raccoondog
raccoondog

スコア77

title CHANGED
File without changes
body CHANGED
@@ -48,28 +48,14 @@
48
48
  ```
49
49
  ※質問内容追記
50
50
  ```ここに言語を入力
51
- ➀ログファイル監視のロジック部分(コーディング方法)が無限ループする記述しかわからず、ある特定の処理(コマンド実行)が終わったら、コマンド実行後出力されるログファイルを監視するだけにしたいです。(1のシェルスクリプトで完結させた。)
51
+ ➀ログファイル監視につい
52
52
 
53
- setenv TARGET_LOG "/log/test.log"
53
+ test.cmd >> test.log
54
- setenv _error_conditions "Error"
55
54
 
56
- hit_action() {
57
- while read i
58
- do
59
- echo $i | grep -q "${_error_conditions}"
55
+ test.logファイルを特定の文字列(Error)で検索し、エラーがあった場合にエラー内容をメール送信させたい
60
- if [ $? = "0" ];then
61
- echo "エラー検知" >> ${MAIL_TMP_FILE}
62
- ${MAIL_CMD} -f `hostname`@xxx.com ${ADDR} < ${MAIL_TMP_FILE}
63
- fi
64
- done
65
- }
66
56
 
67
- if [ ! -f ${TARGET_LOG} ]; then
68
- touch ${TARGET_LOG}
57
+ ※前回検索した行以降としたいです。
69
- fi
70
58
 
71
- tail -n 0 --follow=name --retry $TARGET_LOG | hit_action
72
-
73
59
  ➁日付のセットについて
74
60
  setenv TIME 'date "+%y/%m/%d %H:%M:%S"`
75
61
  指定があいまいです。

4

質問更新

2019/03/01 02:26

投稿

raccoondog
raccoondog

スコア77

title CHANGED
File without changes
body CHANGED
@@ -104,24 +104,26 @@
104
104
  Received: from esa9.hc3012-19.iphmx.com (esa9.hc3012-19.iphmx.com [139.138.32.61])
105
105
  by dmail03.kagoya.net (Postfix) with ESMTP id D7B224242862
106
106
  for <xxx.xxx@xxx.com>; Fri, 1 Mar 2019 10:49:19 +0900 (JST)
107
- Received: from unknown (HELO ykhdc21ws012016.jp.yazaki.com) ([106.186.192.36])
107
+ Received: from unknown (HELO xxxxxx.jp.xxxxx.com) ([106.186.192.36])
108
108
  by esa9.hc3012-19.iphmx.com with ESMTP; 01 Mar 2019 10:49:19 +0900
109
- Received: from ykhdc21ws024015.jp.yazaki.local ([10.194.24.15])
109
+ Received: from ykhdc21ws024015.jp.xxxxx.local ([10.194.24.15])
110
- by ykhdc21ws012016.jp.yazaki.com (sendmail) with ESMTP id x211nH9M024973
110
+ by xxxxxx.jp.xxxxx.com (sendmail) with ESMTP id x211nH9M024973
111
111
  for <xxx.xxx@xxx.com>; Fri, 1 Mar 2019 10:49:17 +0900
112
- Received: from srdcs04.sys.yzk.co.jp (10.1.31.75) by exchange.jp.yazaki.com
112
+ Received: from xxx.xx.xx.co.jp (10.1.31.75) by exchange.jp.xxxxx.com
113
113
  (10.194.24.15) with Microsoft SMTP Server (TLS) id 14.3.158.1; Fri, 1 Mar
114
114
  2019 10:49:17 +0900
115
- Received: from srdcs04.sys.yzk.co.jp (localhost [127.0.0.1]) by
115
+ Received: from xxx.xx.xx.co.jp (localhost [127.0.0.1]) by
116
- srdcs04.sys.yzk.co.jp (8.14.5+Sun/8.14.5) with ESMTP id x211nG1M022559 for
116
+ xxx.xx.xx.co.jp (8.14.5+Sun/8.14.5) with ESMTP id x211nG1M022559 for
117
117
  <xxx.xxx@xxx.com>; Fri, 1 Mar 2019 10:49:16 +0900 (JST)
118
- Received: (from srdcs@localhost) by srdcs04.sys.yzk.co.jp
118
+ Received: (from xxxx@localhost) by xxx.xx.xx.co.jp
119
119
  (8.14.5+Sun/8.14.5/Submit) id x211nGnv022558 for xxx.xxx@xxx.com
120
120
  Fri, 1 Mar 2019 10:49:16 +0900 (JST)
121
121
  Date: Fri, 1 Mar 2019 10:49:16 +0900
122
122
  From: <xxx@xxx.xx.xxx.co.jp>
123
- Message-ID: <201903010149.x211nGnv022558@srdcs04.sys.yzk.co.jp>
123
+ Message-ID: <201903010149.x211nGnv022558@xxx.xx.xx.co.jp>
124
124
  MIME-Version: 1.0
125
125
  Content-Type: text/plain; charset="utf-8"
126
126
  To: Undisclosed recipients:;
127
+
128
+
127
129
  ```

3

質問内容の更新

2019/03/01 02:12

投稿

raccoondog
raccoondog

スコア77

title CHANGED
File without changes
body CHANGED
@@ -87,4 +87,41 @@
87
87
 
88
88
  ⇒メール本文内容が文字化けします。。。
89
89
  ```
90
+
91
+ ➁についてメールヘッダー
92
+ ```ここに言語を入力
93
+ Return-Path: <xxx@xxx.xx.xxx.co.jp>
94
+ Delivered-To: xxx@xxx.net
95
+ Received: from mas16.kagoya.net
96
+ by mas16.kagoya.net with LMTP id eNNjMqKPeFxTGAAAA3Lt0w
97
+ for <xxx@xxx.net>; Fri, 01 Mar 2019 10:49:22 +0900
98
+ Received: from fmail02.kagoya.net (fmail02.kagoya.net [203.142.195.186])
99
+ by mas16.kagoya.net (Postfix) with ESMTP id 65FC640762DF
100
+ for <xxx@xxx.net>; Fri, 1 Mar 2019 10:49:20 +0900 (JST)
101
+ Received: from dmail03.kagoya.net (dmail03.kagoya.net [210.134.58.253])
102
+ by fmail02.kagoya.net with ESMTP id x211nKsV019758-x211nKsW019758
103
+ for <xxx@xxx.net>; Fri, 1 Mar 2019 10:49:20 +0900
104
+ Received: from esa9.hc3012-19.iphmx.com (esa9.hc3012-19.iphmx.com [139.138.32.61])
105
+ by dmail03.kagoya.net (Postfix) with ESMTP id D7B224242862
106
+ for <xxx.xxx@xxx.com>; Fri, 1 Mar 2019 10:49:19 +0900 (JST)
107
+ Received: from unknown (HELO ykhdc21ws012016.jp.yazaki.com) ([106.186.192.36])
108
+ by esa9.hc3012-19.iphmx.com with ESMTP; 01 Mar 2019 10:49:19 +0900
109
+ Received: from ykhdc21ws024015.jp.yazaki.local ([10.194.24.15])
110
+ by ykhdc21ws012016.jp.yazaki.com (sendmail) with ESMTP id x211nH9M024973
111
+ for <xxx.xxx@xxx.com>; Fri, 1 Mar 2019 10:49:17 +0900
112
+ Received: from srdcs04.sys.yzk.co.jp (10.1.31.75) by exchange.jp.yazaki.com
113
+ (10.194.24.15) with Microsoft SMTP Server (TLS) id 14.3.158.1; Fri, 1 Mar
114
+ 2019 10:49:17 +0900
115
+ Received: from srdcs04.sys.yzk.co.jp (localhost [127.0.0.1]) by
116
+ srdcs04.sys.yzk.co.jp (8.14.5+Sun/8.14.5) with ESMTP id x211nG1M022559 for
117
+ <xxx.xxx@xxx.com>; Fri, 1 Mar 2019 10:49:16 +0900 (JST)
118
+ Received: (from srdcs@localhost) by srdcs04.sys.yzk.co.jp
119
+ (8.14.5+Sun/8.14.5/Submit) id x211nGnv022558 for xxx.xxx@xxx.com
120
+ Fri, 1 Mar 2019 10:49:16 +0900 (JST)
121
+ Date: Fri, 1 Mar 2019 10:49:16 +0900
90
- cshでの監視スクリプトについて、ご教示の程宜しくお願い致します。
122
+ From: <xxx@xxx.xx.xxx.co.jp>
123
+ Message-ID: <201903010149.x211nGnv022558@srdcs04.sys.yzk.co.jp>
124
+ MIME-Version: 1.0
125
+ Content-Type: text/plain; charset="utf-8"
126
+ To: Undisclosed recipients:;
127
+ ```

2

質問内容更新

2019/03/01 02:10

投稿

raccoondog
raccoondog

スコア77

title CHANGED
File without changes
body CHANGED
@@ -48,8 +48,28 @@
48
48
  ```
49
49
  ※質問内容追記
50
50
  ```ここに言語を入力
51
- ➀ログファイル監視のロジック部分(コーディング方法)がわからいです。
51
+ ➀ログファイル監視のロジック部分(コーディング方法)が無限ループする記述しかわからず、ある特定の処理(コマンド実行)が終わったら、コマンド実行後に出力されるログファイルを監視するだけにしたいです。(1つのシェルスクリプトで完結させたい。)
52
52
 
53
+ setenv TARGET_LOG "/log/test.log"
54
+ setenv _error_conditions "Error"
55
+
56
+ hit_action() {
57
+ while read i
58
+ do
59
+ echo $i | grep -q "${_error_conditions}"
60
+ if [ $? = "0" ];then
61
+ echo "エラー検知" >> ${MAIL_TMP_FILE}
62
+ ${MAIL_CMD} -f `hostname`@xxx.com ${ADDR} < ${MAIL_TMP_FILE}
63
+ fi
64
+ done
65
+ }
66
+
67
+ if [ ! -f ${TARGET_LOG} ]; then
68
+ touch ${TARGET_LOG}
69
+ fi
70
+
71
+ tail -n 0 --follow=name --retry $TARGET_LOG | hit_action
72
+
53
73
  ➁日付のセットについて
54
74
  setenv TIME 'date "+%y/%m/%d %H:%M:%S"`
55
75
  指定があいまいです。

1

質問内容の更新

2019/03/01 01:27

投稿

raccoondog
raccoondog

スコア77

title CHANGED
File without changes
body CHANGED
@@ -46,4 +46,25 @@
46
46
  :正常終了
47
47
  exit 0
48
48
  ```
49
+ ※質問内容追記
50
+ ```ここに言語を入力
51
+ ➀ログファイル監視のロジック部分(コーディング方法)がわからないです。
52
+
53
+ ➁日付のセットについて
54
+ setenv TIME 'date "+%y/%m/%d %H:%M:%S"`
55
+ 指定があいまいです。
56
+ と言われます。
57
+
58
+ ➂sendmailコマンドのメール本文送付設定について
59
+
60
+ setenv MAIL_CMD "/usr/sbin/sendmail"
61
+ setenv MAIL_TMP_FILE "/mail_tmp_file"
62
+ setenv CHECK_LOG "/check.log"
63
+ setenv ADDR "xxx@xxx.com"
64
+
65
+ echo "メール送信テスト" >> ${MAIL_TMP_FILE}
66
+ ${MAIL_CMD} -f `hostname`@xxx.com ${ADDR} < ${MAIL_TMP_FILE}
67
+
68
+ ⇒メール本文内容が文字化けします。。。
69
+ ```
49
70
  cshでの監視スクリプトについて、ご教示の程宜しくお願い致します。