Wednesday, May 7, 2014

Overriding logback file embedded in jar file


I was trying to run a jar file by setting it up in cronjob. Now this jar file contains a logback configuration file included in it which is causing me problem because all logs are being written to a specific file name, like processnamelogs.log. All runs of jar file will append to the same log file.

Now this is not what I wanted since the log file is going to grow huge in few runs. Also if all runs of jar file are writing to same log file it will be difficult to setup a monitoring script to check for errors.

What I wanted is that each run of jar file writes to a separate log file with its name containing start time of that run. So it will be easy to go through logs in case of errors. Also I can easily setup a monitoring script to only search in the log files with current date in their names.

So I need to write my own logback configuration file and a way to make sure the jar file uses my configuration file instead of embedded one. I have searched and got one system property (logback.configurationFile) which does what I wanted.

e.g.,
  java  -Xms128m -Xmx512m -XX:MaxPermSize=256m -jar -Dlogback.configurationFile=./mylogback.xml ./process.jar

mylogback.xml


<configuration>

  <!-- Insert the current time formatted as "yyyyMMdd'T'HHmmss" under
       the key "bySecond" into the logger context. This value will be
       available to all subsequent configuration elements. -->
  <timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <!-- use the previously created timestamp to create a uniquely
         named log file -->
    <file>log-${bySecond}.txt</file>
    <encoder>
      <pattern>%logger{35} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="DEBUG">
    <appender-ref ref="FILE" />
  </root>
</configuration>






References:
  • http://logback.qos.ch/manual/configuration.html#configFileProperty
  • http://logback.qos.ch/manual/appenders.html#uniquelyNamed












Wednesday, April 30, 2014

find out number of occurrences of a character in mysql


How to find out count of a specific character or a char-sequence in mysql?

There is no simple method available to do that. However we can use below method to find out.

select length(x) - length(replace(x, ":", ""))

Thursday, April 10, 2014

What is Heartbleed Bug


It is basically a security bug (buffer overread) which is in the Open SSL implementation which is used by a looooooooot of websites on the internet to secure ( :) ) the communication between browser and website.

Jacob on stackexchange explained this issue in detail. Read his answer at superuser.com

Sunday, January 26, 2014

to view only directories in Unix


If you have ever wanted to show a list of subdirectories underneath the current directory while at the terminal prompt, there’s a simple command that can help.
Simply run the following command from the bash terminal prompt, which filters the file listing to only show folders:

ls -l | grep ^d
Since typing that whole command every time you want to show a list of directories might get a little tiring, you can use the alias feature to assign it to something you can more easily remember:
alias lsd="ls -l | grep ^d"
Now when you type “lsd” at the prompt, you will see a list containing only the directories, which can be very useful when you are trying to navigate through a messy set of folders.

Sunday, January 19, 2014

Some useful VI editor commands


J – to join two lines
Deletion
dl – single character, dw – Single word, dd – single line, d$ – to the end of the line
Editing
i – insert mode, A – append to the end of the line, o – insert in next line
Misc
:set list – to see special characters
:%s/str1/str2/g – search and replace

Sunday, January 12, 2014

Some useful variables in Unix


$$ = The PID number of the process executing the shell.
$? = Exit status variable.
$0 = The name of the command you used to call a program.
$1 = The first argument on the command line.
$2 = The second argument on the command line.
$n = The nth argument on the command line.
$* = All the arguments on the command line.
$# The number of command line arguments.

Sunday, January 5, 2014

Read password from shell script


Since you don't want password to be not displayed on terminal you need to disable echo before reading password. Once password is read you need to enable it again.

#————————————————————
#  Read Password
#————————————————————
/usr/ucb/echo -n “Please Enter Password For User ${SUSER}: “
stty -echo
read SPSWD
stty echo
clear

Friday, December 2, 2011

How to do MySQL port forwarding using PuTTY

1. Go to Session: enter site name, port, etc…
2. Window > Behaviour : Window Title can be set here.
3. Connection > Data: User name should be given Auto-login username.
4. Connection > SSH : check Enable Compression.
5. Connection > SSH > Tunnels: enter local port number in Source Port, the port to be forwarded in Destination in the form : and click on Add to create the tunnel.
For MySQL client, this local port will be the port and localhost will be the machine.

Create windows short cut for this.
1. Create a short cut for PuTTY and change its command like below.
C:\Users\user\Desktop\putty.exe -ssh -pw -load
Source: http://www.jfitz.com/tips/putty_config.html

Thursday, July 7, 2011

Find recursively and copy files in Unix

I was trying to do a recursive search in Unix using find command and then copy all those files to a specific folder.

I found below command does that.

find . -name *2011-03-19* -exec cp {} /home/Reddy/logs/ \;

Important thing is, we need to escape the ending semi-colon.

{} is the place holder for putting the search result, i.e., the file name found.

Wednesday, October 1, 2008

Enable the tools disabled by virus

If you got a virus usually it will disable the following things so that you can't be able to delete the virus.

It will disable Folder Options menu item from View menu, disables the Task Manager, and disables the Registry Editor.

You can enable all these from the Group Policy editor by yourself manually.

  • Go to Windows > Run > gpEdit.msc
  • Folder Options: Go to User Configuration > Administrative Templates > Windows Components > Windows Explorer > Removes the Folder Options menu item from the Tools menu. Disable this option. Now you should be able to see Folder Options in the View menu of your explorer window.
  • Task Manager: Go to User Configuration > Administrative Templates > System > Ctrl+Alt+Del Options > Remove Task Manger. Disable this option.
  • Registry Editor: Go to User Configuration > Administrative Templates > System > Prevent Access to Registry Editing Tools. Disable this option.
But, it is good to have alternatives for these things since viruses usually disables the default tools but not the alternative softwares.

You can use Process Explorer as alternative for Task Manager. Similarly you can use Explorer2 as alternative for default windows explorer. If you don't like Explorer2 many more explorer softwares are available, you can choose from any of those. I don't know alternatives for the Registry Editor. Please feel to share those you know in the comments section below.

Related Posts:
Stop viruses coming from Pen Drives
Remove Amvo.exe virus, Funny UST Scandal, Fun.exe DC.exe SVIQ.exe
Task Manager, Registry Accessing disabled?
Disable Autoplay, Messenger Service
Important steps while cleaning virus
What is this process

Subscribe to my site feed for receiving more tips. You can get more tips in your email for free.

Latest Posts