Unix

How to tail a server log file and show only intended entries?

Most of us working with JBoss or Tomcat server / container need to check log files for debugging information. What if we want the system to be able to filter out only the lines we want to see?

A typical log file generated by the server looks like this:

DEBUG [15:13:56] [prod.idms.service.impl.AuditLogServiceImpl.triggerEvent]= Checking against monitor: IDMS_USER_UPDATE_PWD
DEBUG [15:13:56] [prod.idms.service.impl.AuditLogServiceImpl.triggerEvent]= Checking against monitor: IDMS_USER_REGISTER_ADMIN
DEBUG [15:13:56] [prod.idms.service.impl.AuditLogServiceImpl.triggerEvent]= Checking against monitor: IDMS_USER_REGISTER
DEBUG [15:13:56] [prod.idms.service.impl.AuditLogServiceImpl.triggerEvent]= Checking against monitor: IDMS_USER_SUSPENDED
DEBUG [15:13:56] [prod.idms.service.impl.AuditLogServiceImpl.triggerEvent]= Checking against monitor: SYSTEM_BOOT_UP
DEBUG [15:13:56] [prod.idms.service.impl.AuditLogServiceImpl.triggerEvent]= Checking against monitor: SYSTEM_SHUTDOWN
 INFO [15:13:56] [org.springframework.orm.hibernate3.AbstractSessionFactoryBean.destroy]= Closing Hibernate SessionFactory
 INFO [15:14:02] [org.jboss.resource.connectionmanager.ConnectionFactoryBindingService.unbindConnectionFactory]= Unbound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=jdbc/ebarges' from JNDI name 'java:jdbc/ebarges'
 INFO [15:14:02] [org.jboss.resource.connectionmanager.ConnectionFactoryBindingService.unbindConnectionFactory]= Unbound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' from JNDI name 'java:JmsXA'
 INFO [15:14:02] [org.jboss.mq.server.jmx.DestinationMBeanSupport.stopService]= Unbinding JNDI name: topic/testTopic
 INFO [15:14:02] [org.jboss.mq.server.jmx.DestinationMBeanSupport.stopService]= Unbinding JNDI name: topic/securedTopic
 INFO [15:14:02] [org.jboss.mq.server.jmx.DestinationMBeanSupport.stopService]= Unbinding JNDI name: topic/testDurableTopic
 INFO [15:14:02] [org.jboss.mq.server.jmx.DestinationMBeanSupport.stopService]= Unbinding JNDI name: queue/testQueue
 INFO [15:14:02] [org.jboss.mq.server.jmx.DestinationMBeanSupport.stopService]= Unbinding JNDI name: queue/A
 INFO [15:14:02] [org.jboss.mq.server.jmx.DestinationMBeanSupport.stopService]= Unbinding JNDI name: queue/B
 INFO [15:14:02] [org.jboss.mq.server.jmx.DestinationMBeanSupport.stopService]= Unbinding JNDI name: queue/C
 INFO [15:14:02] [org.jboss.mq.server.jmx.DestinationMBeanSupport.stopService]= Unbinding JNDI name: queue/D
 INFO [15:14:02] [org.jboss.mq.server.jmx.DestinationMBeanSupport.stopService]= Unbinding JNDI name: queue/ex

Lets say we want to only see on the fly generated log entries beginning with DEBUG?

$ tail -f ebarges.log | grep ^DEBUG

The results?

$ tail -f ebarges.log | grep ^DEBUG
DEBUG [15:20:34] [prod.ebarges.util.poller.DirectoryPoller.a]= [-- Monitoring "C:\c1\dev_project\ebarges\application_data\server\Incoming" --]
DEBUG [15:20:34] [prod.ebarges.util.poller.DirectoryPoller.a]= [-- Monitoring "C:\c1\dev_project\ebarges\application_data\server\Processed_Retry" --]
DEBUG [15:20:34] [prod.idms.service.impl.AuditLogServiceImpl.init]= AuditLogServiceImpl Registering: IDMS_USER_LOGIN
DEBUG [15:20:34] [prod.idms.service.impl.AuditLogServiceImpl.init]= AuditLogServiceImpl Registering: IDMS_USER_LOGOUT
DEBUG [15:20:34] [prod.idms.service.impl.AuditLogServiceImpl.init]= AuditLogServiceImpl Registering: IDMS_USER_LOGIN_FAILURE
DEBUG [15:20:34] [prod.idms.service.impl.AuditLogServiceImpl.init]= AuditLogServiceImpl Registering: IDMS_USER_UNAUTHORIZED_ACCESS
DEBUG [15:20:34] [prod.idms.service.impl.AuditLogServiceImpl.init]= AuditLogServiceImpl Registering: IDMS_USER_UPDATE_PWD
DEBUG [15:20:34] [prod.idms.service.impl.AuditLogServiceImpl.init]= AuditLogServiceImpl Registering: IDMS_USER_REGISTER_ADMIN
DEBUG [15:20:34] [prod.idms.service.impl.AuditLogServiceImpl.init]= AuditLogServiceImpl Registering: IDMS_USER_REGISTER
Share

Unix Command Find And Delete The Efficient Way With xargs

$find . -name “*.h” -print0 | xargs -0 rm

Conventionally to delete a file in linux you would issue the rm command, rm for ReMove.

This command below is for removing one file, named abc.c

$rm abc.c

To remove multiple files, we may pipe in the known list of files into the arguments of rm.

$rm abc.c dfr.c snh.c

To remove all files in the directory you may issue a wild card in many forms.

$rm *.c

$rm *.*

$rm *

What if you wish to find and delete, such that you would like to use the more complex features of Unix find command to locate files and then deleting them in a single OR minimal remove command.

When issuing this command, the executor attempts to find all the files that qualify under the specified directory and then pipes into xargs which pipes as many file directory into rm as possible for single execution.

Introducing the Find + Remove command

$find -name “< qualifier >” -print0 | xargs -0 rm

Sample Usage.

$find /home/ken -name “*.cpp” -print | xargs -0 rm (Mistake / Erroneous)

$find /home/ken -name “*.cpp” -print0 | xargs -0 rm

$find /home/ken -name “touch.*” -print | xargs -0 rm (Mistake / Erroneous)

$find /home/ken -name “touch.*” -print0 | xargs -0 rm

But Why Use This Instead of Say -exec rm ‘{}’ \;

As mentioned, the advantage of xargs is it passes and packs as many arguments into rm as possible. Using -exec executes a remove command for each file found, which is less efficient.

Thanks to Eugene for teaching me this! Cheers.

Corrected with comments from ole.tange.dk (With thanks!)

Last Edited 2010-10-25 10:05:00AM

Share
Untitled-2

Configuring MySQL To Start At Boot Up

One of the cornerstones of MySQL installation is enabling automatic startup with server boot up. This is important if are have many services running under a server and have many servers for that matter.

Assumption

CentOS Linux 5

MySQL 5

Shell Access / PuTTY / Console Access

Step 1 SSH To Linux Server And Switch User To Root

SSH to your Linux Server and switch user to root

#su -

Step 2 Check Config For mysqld Run Level

#chkconfig –list mysqld

As you may see from chkconfig, mysqld is off for run levels 1 to 6. We need to turn it on for 2, 3, 4, and 5.

Step 3 Turn On Run Level For 2, 3, 4, 5

#chkconfig –level 2345 mysqld on

Done, next, ensure that mysqld is turned on by issuing the chkconfig –list mysqld command again.

#chkconfig –list mysqld


mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off


Share
  • Newsflash

    March 2012: We have change our site theme to F2.
  • Who's Online

    2 visitors online now
    2 guests, 0 members
    Powered by Visitor Maps