Get the CPU information in Linux

Multi-core CPU processors are common nowadays, including dual-core processors, quad-core processors, and hexa-core processors. Also, many server physical machines are equipped with more than one CPU processor. In order to find the number CPUs, and the number of cores per CPU, you can refer to /proc/cpuinfo. A sample /proc/cpuinfo of HP Proliant DL 380 G7 server is as follows. 


To find the number of physical CPUs:
$ cat /proc/cpuinfo | grep "^physical id" | sort | uniq | wc -l
2

To find the number of cores per CPU:
$ cat /proc/cpuinfo | grep "^cpu cores" | uniq
cpu cores : 4

The total number of processors available is the number of physical CPUs multiplied by the number of cores per CPU.

To find the total number of processors:
$ cat /proc/cpuinfo | grep "^processor" | wc -l
16

Note that Intel Xeon 5600 series processors have Intel Hyper-Threading capability. So each core shows up as "two" processors in Linux, and thus the total processor count seen by Linux is 16 (= 2 x 4 x 2).

Compare Files between two directories using md5sum

If you come across situation where you need to compare two directories in two different servers. md5sum command can be used, which will generate md5sum of files in directories and write it to one file. In turn that file can be used to check md5sum at destination. 

Run below command at source location:

find /opt/ -type f -print0 | xargs -0 md5sum > /root/checksums_backup.md5

Once you run above command, it will create /root/checksums_backup.md5 file. You can copy this file to destination server and run below command to check md5sum. 
Note: Source and Destination server should have the same directory structure.

md5sum -c /root/checksums_backup.md5

After running above command, you will see "OK" and "FAILED" output. According to that you can easily make out which files are different from source location.

Check Disk Performance in Linux

We use iostat command to check the disk performance.

Reports that we get from ‘iostat’ are really useful but I myself had a little bit of trouble when trying to interpret the results while using the the first time.


I usually use the iostat command with the following switches:
iostat –d –x <interval>
Where in…
-d = gets rid of the CPU stats so that we can easily concentrate on the I/O only
-x = some additional info like ‘await’ and ‘svctm’ (will discuss them later)
<interval> = this is time in seconds, so every number of <interval> seconds you will get a new ‘iostat’ report
Let’s now see a sample output of ‘iostat’:
If we look at stats above usually we would look at %util and if we see close to 100% it can identify the problem for a single disk setup, but not in a usual multi-disks scenario.
Columns that we look at it in order to identify the problem will be:
syvctm: The average service time (in milliseconds) for I/O requests that were issued to the device
await: The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.
This basically means:
 await = syvctm + wait time in queue
Now using the above we can have a basic rule to identify an overloaded setup:
…if you can see a lot of difference in values for ‘syvctm’ and ‘await’ every now and then, that can tell you about I/O requests being going into long waits and this should help you identify the problem.

Japanese Fonts in Putty

I am going to show you here, how to show Japanese characters in file using putty.

(1) First open Putty. Give "Host Name" of the server where you are going to connect.
(2) Click on "Window"->"Translation" in Putty. Select "UTF-8" in Remote Character Set.

(3) Now goto "Windows"->"Appearance" and change Fonts. Set "Ms Gothic" fonts and set "script" to "Japanese" as shown in below figure.

(4) Then open putty session. open Vi editor, and set character encoding in Vim using below command.

:set enc=utf-8

Now you should be able to see Japanese characters in Putty.

Test Multicast in Network



You will come across situation, where you need to identify if multicasting has been enabled or not. Sometimes, its disabled due to some security reasons and to avoid network traffic congestion.

Follow below steps to identify if multicasting enabled or not.

Run the following receiver command on the one server:
java -classpath /root/jgroups-2.11.1.Final.jar org.jgroups.tests.McastReceiverTest -mcast_addr 224.10.10.10 -port 5555

Once the receiver command blocks, simultaneously run the following sender command on another host:
java -classpath /root/jgroups-2.11.1.Final.jar org.jgroups.tests.McastSenderTest -mcast_addr 224.10.10.10 -port 5555

Now two applications should be able to connect and arbitrary lines entered on the sender should appear on the receiver.

Download: jgroups-2.11.1.Final.jar

Give public access to Amazon S3 bucket

Giving each individual file public access becomes cumbersome in Amazon S3. I wanted to give public access to all files in Amazon S3 bucket, I was doing that manually for each file through shell script. But later on I found the way to give permission on bucket it self, so that it can make all files "public" in bucket. You can do it following below steps.


  1. Do right click on bucket -> Properties.
  2. Click on "Edit Bucket Policy". Add below policy and click on "save" button. Done!!!

Using "X-Forwarded-For" in Apache

This post gone be helpful if your incoming traffic is coming from NATed IP and you want to get the actual IP instead of the NATed one for some reason.

Before few days, I created two web server and one load balancer in Amazon EC2. Load balancer was forwarding traffic to two web servers. That was working fine, but due to nature of Amazon ELB we could not get the actual Source IP from where our site was being accessed.

So by googling, we found that using "X-Forwarded-For" we can get the original source's IP Address and we can utilize it for further use(may be for troubleshooting or for Geocoding or for webalizer to create informative graphs). It was just a 3 line of code, which did a trick. You can use that in apache configuration.

11 Facts of Rajani

1. Rajinikanth can send e-mail without mail id
2. Only Rajinikanth can kill the dead!
3. Rajini's favourite SQL query... SELECT * from ORACLE;
4. Rajinikanth's father was never happy with his hairstyle but never asked him to get a haircut. Why? 'Cause he knew his son will grow them again overnight....... ;-D
5. Once Rajinikanth dropped a coin while he was standing in the balcony. He went down to pick it up, but it was not there! Reason? He reached there before the coin!
6. Only Rajini can draw a straight circle
7. Only Rajinikanth can send can mms from a landline phone
8. When Rajinikanth was a Student, Teachers use to Bunk the classes!!!
9. Only Rajinikanth knows who let the dogs out!
10. When Alexander Graham Bell first used his telephone, he realized that he already had two missed calls from Rajinikanth.
11.

*Only Rajani can read 11th

Setup SSH tunnel to access Remote Desktop through Putty

This post will be helpful if your windows machine is behind firewall and port 3389 is blocked. Although you can access windows machine, but you should have atleast one linux machine access behind firewall. You can access windows machine through SSH tunneling. Ofcourse, port 22 should be accessible!
You can follow below steps to do SSH tunneling using Putty.
(1) open putty. Give the IP address of Linux machine.


(2) Now click on Tunnels under SSH. Give IP address of Windows machine and port . and Give mapped port.


(3) Now click on "Add" button and the click on "Open" button.


(4) Now open "Remote Desktop Connection" and give "localhost:3391" then try to connect. You will see window's logon screen!

Pidgin - A replacement of Yahoo messenger

Nowadays I have started using Pidgin as IM. I was using yahoo but it was consuming near about 60M memory. So I was looking for alternate solution and I found Pidgin. It takes around 13M memory. So pretty light weight.
I installed it, and was not comfortable with look and feel of it. I searched for applying skin to it. And I did it through below steps.
As of version 2.7.0, Pidgin ships with a private GTK+ runtime and doesn't include extra themes or a GUI theme switching application.
There is an easy way to use the GTK+ theme binaries and theme switcher.
Download the GTK+ Themes and GTK+ Theme Switcher zip files and extract them to a temporary directory.
Copy the lib and share directories from the GTK+ Themes zip file into your \Gtk directory (you want to merge those with the existing lib and share directories). Copy the gtk2_prefs.exe from the GTK Theme Switcher zip file into your \Gtk\bin directory.
You can now run the gtk2_prefs.exe applications to choose a theme. You probably will want to use the "Apply for all users" checkbox so that the changes are made to Pidgin's private GTK+ runtime.
Note: If you had previously set up a user-specific GTK+ theme with the global GTK+ Runtime, you will need to delete or rename the %USERPROFILE%/.gtkrc-2.0 file in order to have your changes take effect.

Cron Job Output to mail

I was looking for a output of Cron Job, whenever it runs. The output can be a general output of script or any error generated by script.

There's standard output (STDOUT) and standard errors (STDERR). STDOUT is marked 1, STDERR is marked 2. So the following statement tells Linux to store STDERR in STDOUT as well, creating one datastream for messages & errors:


2>&1

Lets say if you want to send cron output to mail then edit below entry in crontab.


13 15 * * * /root/my.sh 2>&1 | mail -s "Cronjob ouput" alpesh.bhavsar@yahoo.c0m


Monitoring JMX port in Amazon EC2 hosted server

Recently I have started work on Amazon EC2 servers. At some point I got requirement to monitor JMX port of server which was hosted on Amazon EC2. I followed the steps which was previously posted in my blog. But it did not help. I tried changing CATALINA_OPTS parameters as well as I opened all ports in Amazon "Security Group". After all I got help from Feil Figg blog. So below are steps to achieve it.

(1) First download catalina-jmx-remote.jar file as per tomcat's version and keep it in tomcat\lib folder.

(2) Now open tomcat/conf/server.xml file and add below line into it.

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="8999" rmiServerPortPlatform="8999"/>



(3) Now open tomcat/bin/setenv.sh file and add below java parameters.



JAVA_OPTS="${JAVA_OPTS} -Djava.rmi.server.hostname=ec2-xx-xxx-x-xxx.compute-1.amazonaws.com -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

(4) Now restart tomcat. You need to open port 8999 in Amazon "Security Group".

Hope this will help.






Register Alfresco FSR as Windows Service running on 64 bit using YAJSW

(1) First download the latest stable build of YAJSW from here.
(2) Unzip yajsw-stable-11.0.zip in D:\apps\yajsw folder.
(3) Install Alfresco FSR into D:\apps\FSR folder. (Ex. D:\apps\FSR)
(4) Copy all *.jar files from D:\apps\FSR folder to D:\apps\yajsw\lib folder.
(5) Copy application-context.xml and shutdown-context.xml files from D:\apps\FSR to D:\apps\yajsw\bat folder.
(6) Now open coammand prompt. Goto D:\apps\FSR directory and run below command.

jar cf deployment-config.jar deployment.properties deployment/*

Above command will create “deployment-config.jar” jar file in D:\apps\FSR directory.
(7) Now Start FSR manually and check its PID in “Task Manager”. Note down the PID of Alfresco FSR.
(8) Now goto D:\apps\yajsw\bat folder and run below command.

genConfig.bat “PID of Alfresco FSR”

Ex: genConfig.bat 1492

(9) This will generate the wrapper.conf file under D:\apps\yajsw\conf folder. Now Open wrapper.conf file and set below path.
Note: please make changes of path as per your configuration.

wrapper.working.dir=D:\\apps\\FSR\\
wrapper.java.app.mainclass=org.alfresco.deployment.Main
wrapper.console.title=Alfresco Deployment Server
wrapper.ntservice.name=Alfresco Deployment Server
wrapper.ntservice.displayname=Alfresco Deployment Server
wrapper.ntservice.description=Alfresco Deployment Server
wrapper.java.command = C:\\Program Files\\Java\\jdk1.6.0_22\\bin\\java
wrapper.app.parameter.1 = application-context.xml
wrapper.java.additional.1=-server
wrapper.java.additional.2 = -Djava.ext.dirs=.;C:\\Program Files\\Java\\jdk1.6.0_22\\jre\\lib\\ext


(10) Execute Alfresco FSR as console application by calling and confirm that Alfresco FSR is running correctly.

D:\apps\yajsw\bat\runConsole.bat

(11) If everything is ok then install Alfresco FSR as Windows Service call using below command.

D:\apps\yajsw\bat\installService.bat

Done!!!

Google

tail command in Windows using Notepad++

How to use tail command in Windows using Notepad++
 (1) Download DocMonitor plugin using below link.
 http://sourceforge.net/projects/npp-plugins/files/DocMonitor/
 (2) Open Notepad++. Go to Setting -> Inport -> Import Plugin. Give downloaded dll file's path and restart notepad++.
 (3) Now open document in notepad++ you want to monitor and click on Plugins -> Document Monitor -> start Monitoring.