Tuesday 19 March 2013

Show the line number while monitoring the log files using tail -f command?

Question:


How to show the line number while monitoring the log files using tail -f command?

Answer:


You can combine the tail -f command using either cat or awk commands:

Method 1:

# tail -f syslog|cat -n


Method 2: 

# tail -f syslog|awk '{print NR,$0}'


You should get the similar output as below:

 1 Mar 4 15:21:07 oraserver local1:info Oracle Audit[1433636]: LENGTH: "357" SESSIONID:[8] "75222038" ENTRYID:[1] "1" STATEMENT:[1] "1" USERID:[4] "APPS" USERHOST:[20] "oraserver.unix.com" TERMINAL:[7] "unknown" ACTION:[3] "100" RETURNCODE:[1] "0" COMMENT$TEXT:[99] "Authenticated by: DATABASE; Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=69.9.172.201)(PORT=40167))" OS$USERID:[7] "apmgr09" DBID:[9] "711595639" PRIV$USED:[1] "5"
2 Mar 4 15:21:07 oraserver local1:info Oracle Audit[4198698]: LENGTH: "357" SESSIONID:[8] "75222037" ENTRYID:[1] "1" STATEMENT:[1] "1" USERID:[4] "APPS" USERHOST:[20] "oraserver.unix.com" TERMINAL:[7] "unknown" ACTION:[3] "100" RETURNCODE:[1] "0" COMMENT$TEXT:[99] "Authenticated by: DATABASE; Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=69.9.172.201)(PORT=40168))" OS$USERID:[7] "apmgr09" DBID:[9] "711595639" PRIV$USED:[1] "5"
3 Mar 4 15:21:07 oraserver local1:info Oracle Audit[5456076]: LENGTH: "203" SESSIONID:[8] "75222036" ENTRYID:[1] "1" ACTION:[3] "101" RETURNCODE:[1] "0" LOGOFF$PREAD:[1] "0" LOGOFF$LREAD:[2] "39" LOGOFF$LWRITE:[1] "0" LOGOFF$DEAD:[1] "0" DBID:[9] "711595639" SESSIONCPU:[1] "0"
4 Mar 4 15:21:07 oraserver local1:info Oracle Audit[6545472]: LENGTH: "203" SESSIONID:[8] "75222035" ENTRYID:[1] "1" ACTION:[3] "101" RETURNCODE:[1] "0" LOGOFF$PREAD:[1] "0" LOGOFF$LREAD:[2] "39" LOGOFF$LWRITE:[1] "0" LOGOFF$DEAD:[1] "0" DBID:[9] "711595639" SESSIONCPU:[1] "0"
5 Mar 4 15:21:09 oraserver local1:info Oracle Audit[5456078]: LENGTH: "364" SESSIONID:[8] "75222039" ENTRYID:[1] "1" STATEMENT:[1] "1" USERID:[10] "APPLSYSPUB" USERHOST:[20] "oraserver.unix.com" TERMINAL:[7] "unknown" ACTION:[3] "100" RETURNCODE:[1] "0" COMMENT$TEXT:[99] "Authenticated by: DATABASE; Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=69.9.172.201)(PORT=40174))" OS$USERID:[7] "apmgr09" DBID:[9] "711595639" PRIV$USED:[1] "5"
6 Mar 4 15:21:09 oraserver local1:info Oracle Audit[1609878]: LENGTH: "357" SESSIONID:[8] "75222040" ENTRYID:[1] "1" STATEMENT:[1] "1" USERID:[4] "APPS" USERHOST:[20] "oraserver.unix.com" TERMINAL:[7] "unknown" ACTION:[3] "100" RETURNCODE:[1] "0" COMMENT$TEXT:[99] "Authenticated by: DATABASE; Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=69.9.172.201)(PORT=40175))" OS$USERID:[7] "apmgr09" DBID:[9] "711595639" PRIV$USED:[1] "5"
7 Mar 4 15:21:09 oraserver local1:info Oracle Audit[5456078]: LENGTH: "203" SESSIONID:[8] "75222039" ENTRYID:[1] "1" ACTION:[3] "101" RETURNCODE:[1] "0" LOGOFF$PREAD:[1] "0" LOGOFF$LREAD:[2] "39" LOGOFF$LWRITE:[1] "0" LOGOFF$DEAD:[1] "0" DBID:[9] "711595639" SESSIONCPU:[1] "0"
8 Mar 4 15:21:17 oraserver auth|security:info sshd[6545478]: Accepted publickey for sesas from 69.27.41.22 port 2504 ssh2
9 Mar 4 15:21:17 oraserver auth|security:info sshd[5456086]: subsystem request for sftp
10 Mar 4 15:21:46 oraserver daemon:info CCIRMTD[295062]: .CAICCI_W_2014[oraserver] Attempt to connect to host <remoteserver.unix.com> failed, Check t

No comments:

Post a Comment