grep command line utility is important utility on linux and unix like systems. It is very helpful to search files based on search patterns or text strings. It is very famous tool because of its vast options capabilities.
grep <keyword> <filename>
grep options –
-e used to pass the pattern
-r recursive sreach
-n line by line search
-w search those line matches and make whole word
Search the log file for keyword error –
cs365servers/webt/logs $ grep error ./webt.log
[2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app]
If the output is very long, you can pipe it with more to see page wise –
cs365servers/webt/logs $ grep error ./webt.log | more
[2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app] [2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app][2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [WEBT99999] [app]
Below example, I want to search port based logs from the logs file – servers/HTTPS1/logs $ grep -rnw . -e “7010” | more
./HTTPS1.log:1680:[2024-03-20T08:57:00.2151+01:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.5.5] [host_id: cs365hst267045.cloudshiksha365.com] [host_addr: 10.
5.5.18] [pid: 1243080] [tid: 139904533133056] [user: ipc_gfrk] [ecid: 00651BcLHdrFg4v5SZL6ic004jV80003mi] [rid: 0] [VirtualHost: cs365hst267045.cloudshiksha365.com:9085] a
p_proxy: trying GET /cs365/f at backend host 10.5.5.18/7010; got exception ‘READ_TIMEOUT [os error=0, line 284 of Reader.cpp]: no read after 120 seconds’; state
: reading status line or response headers from WLS (wrote? Y read? N); failing over
./HTTPS1.log:1682:[2024-03-20T14:02:56.7297+01:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.5.5] [host_id: cs365hst267045.cloudshiksha365.com] [host_addr: 10.
5.5.18] [pid: 1243080] [tid: 139904499562240] [user: ipc_gfrk] [ecid: 00651SiTmnrFg4v5SZL6ic004jV80004mq] [rid: 0] [VirtualHost: cs365hst267045.cloudshiksha365.com:9085] a
p_proxy: trying GET /cs365/ at backend host 10.5.5.18/7010; got exception ‘READ_TIMEOUT [os error=0, line 284 of Reader.cpp]: no read after 120 seconds’; state:
reading status line or response headers from WLS (wrote? Y read? N); failing over
./HTTPS1.log:1684:[2024-03-20T14:21:49.0417+01:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.5.5] [host_id: cs365hst267045.cloudshiksha365.com] [host_addr: 10.
5.5.18] [pid: 1242563] [tid: 139904793110272] [user: ipc_gfrk] [ecid: 00651TlxEIMFg4v5SZL6ic004jN30002Vu] [rid: 0] [VirtualHost: cs365hst267045.cloudshiksha365.com:9085] a
p_proxy: trying GET /cs365/f at backend host 10.5.5.18/7010; got exception ‘READ_TIMEOUT [os error=0, line 284 of Reader.cpp]: no read after 120 seconds’; state
: reading status line or response headers from WLS (wrote? Y read? N); failing over
./HTTPS1.log:1690:[2024-03-20T16:12:21.8796+01:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.5.5] [host_id: cs365hst267045.cloudshiksha365.com] [host_addr: 10.
5.5.18] [pid: 1440900] [tid: 139868076168960] [user: ipc_gfrk] [ecid: 00651ZxJVS^Fg4v5SZL6ic005Vm40000G8] [rid: 0] [VirtualHost:
Below example we will search for string “Connection refused”
servers/HTTPS1/logs $ grep -rnw . -e “Connection refused” | more
./HTTPS1.log:19:[2023-07-14T10:17:06.2158+02:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.229.131] [host_id: cs365vm0267045.cloudshiksha365.com] [host_addr: 10.15
7.129.18] [pid: 163973] [tid: 140204274857728] [user: ipc_gfrk] [ecid: 00606sJ2ysWFg4v5SZL6ic000c2500001d] [rid: 0] [VirtualHost: cs365vm0267045.cloudshiksha365.com:9085] <006 06sJ2ysWFg4v5SZL6ic000c2500001d> parseServerList: cs365vm0267045.cloudshiksha365.com:9001 apr_socket_connect error [111] Connection refused
./HTTPS1.log:81:[2023-08-01T11:09:20.9444+02:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.229.131] [host_id: cs365vm0267045.cloudshiksha365.com] [host_addr: 10.15
7.129.18] [pid: 3215993] [tid: 139887260944128] [user: ipc_gfrk] [ecid: 0060TZb2DUBFg4v5SZL6ic00CH9t0002PZ] [rid: 0] [VirtualHost: cs365vm0267045.cloudshiksha365.com:9085] <00 60TZb2DUBFg4v5SZL6ic00CH9t0002PZ> parseServerList: cs365vm0267045.cloudshiksha365.com:9001 apr_socket_connect error [111] Connection refused
./HTTPS1.log:899:[2023-12-20T14:37:59.1182+01:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.229.131] [host_id: cs365vm0267045.cloudshiksha365.com] [host_addr: 10.1
57.129.18] [pid: 2058248] [tid: 140321119782656] [user: ipc_gfrk] [ecid: 0063F4NO8NiFg4v5SZL6ic007qW8000006] [rid: 0] [VirtualHost: cs365vm0267045.cloudshiksha365.com:9085] <0 063F4NO8NiFg4v5SZL6ic007qW8000006> parseServerList: cs365vm0267045.cloudshiksha365.com:9001 apr_socket_connect error [111] Connection refused
./HTTPS1.log:913:[2023-12-20T14:38:25.3790+01:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.229.131] [host_id: cs365vm0267045.cloudshiksha365.com] [host_addr: 10.1
57.129.18] [pid: 2058476] [tid: 140321898424064] [user: ipc_gfrk] [ecid: 0063F4OwJplFg4v5SZL6ic007qZg000007] [rid: 0] [VirtualHost: cs365vm0267045.cloudshiksha365.com:9085] <0 063F4OwJplFg4v5SZL6ic007qZg000007> parseServerList: cs365vm0267045.cloudshiksha365.com:9001 apr_socket_connect error [111] Connection refused
./HTTPS1.log:959:[2023-12-20T20:12:10.1411+01:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.229.131] [host_id: cs365vm0267045.cloudshiksha365.com] [host_addr: 10.1
57.129.18] [pid: 2141424] [tid: 140516918269696] [user: ipc_gfrk] [ecid: 0063FN2Whk5Fg4v5SZL6ic008Ank00000Y] [rid: 0] [VirtualHost: cs365vm0267045.cloudshiksha365.com:9085] <0 063FN2Whk5Fg4v5SZL6ic008Ank00000Y> parseServerList: cs365vm0267045.cloudshiksha365.com:9002 apr_socket_connect error [111] Connection refused
./HTTPS1.log:979:[2023-12-21T08:01:43.1364+01:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.229.131] [host_id: cs365vm0267045.cloudshiksha365.com] [host_addr: 10.1
57.129.18] [pid: 2230540] [tid: 139837977892608] [user: ipc_gfrk] [ecid: 0063Fyg3nRGFg4v5SZL6ic008W^C000006] [rid: 0] [VirtualHost: cs365vm0267045.cloudshiksha365.com:9085] <0 063Fyg3nRGFg4v5SZL6ic008W^C000006> parseServerList: cs365vm0267045.cloudshiksha365.com:9001 apr_socket_connect error [111] Connection refused
./HTTPS1.log:1044:[2023-12-28T17:32:40.2177+01:00] [HTTPS] [ERROR:32] [OH99999] [weblogic] [client_id: 10.31.229.131] [host_id: cs365vm0267045.cloudshiksha365.com] [host_addr: 10.
157.129.18] [pid: 3634015] [tid: 140407463712512] [user: ipc_gfrk] [ecid: 0063PHqp6fmFg4v5SZL6ic00DrDV000002] [rid: 0] [VirtualHost: cs365vm0267045.cloudshiksha365.com:9085] < 0063PHqp6fmFg4v5SZL6ic00DrDV000002> parseServerList: cs365vm0267045.cloudshiksha365.com:9001 apr_socket_connect error [111] Connection refused