Get Thread and Heap dump – Java

 

Thread and Heap dumps are useful for debugging any Java programme.

To get thread dump:

By using jstack command we can get thread dump of a Java process.

Example:

$ jstack PID

where PID is Java process id for which we want to get thread dump.

To get heap dump:

By using jmap command we can get heap dump of a Java process.

Exmaple:

$ jmap -heap PID

where PID is Java process id for which we want to get heap dump.

ping ip with port

 

Ports are a concept of UDP and TCP. Ping messages are technically referred to as ICMP Echo Request and ICMP Echo Reply which are part of ICMP. ICMP, TCP, and UDP are “siblings”; they are not based on each other, but are three separate protocols that run on top of IP.

Therefore you can not ping a port. What you can do, is use a port scanner like nmap and check if ip/host and port are accessible.

$ nmap -p 80 www.google.com

Output:

Starting Nmap 6.40 ( http://nmap.org ) at 2015-12-02 14:38 IST
Nmap scan report for http://www.google.com (74.125.200.106)
Host is up (0.085s latency).
Other addresses for http://www.google.com (not scanned): 74.125.200.147 74.125.200.104 74.125.200.103 74.125.200.105 74.125.200.99
rDNS record for 74.125.200.106: sa-in-f106.1e100.net
PORT STATE SERVICE
80/tcp open http

Nmap done: 1 IP address (1 host up) scanned in 0.64 seconds

You can also use telnet onofri.org 80

Linux – Ping multiple hosts using fping

 

fping is a ping like program which uses the Internet Control Message Protocol (ICMP) echo request to determine if a host is up.

With fping we can ping multiple hosts at a time. Use following command to ping multiple hosts:

$ fping -f IPsFiles.txt 

where in IPsFiles.txt I have multiple hots.

Below are some other examples of fping:

To ping a host/IP:

$ fping 192.168.2.2

Output:

192.168.2.2 is alive

$ fping 192.168.2.22

Output:

192.168.1.22 is unreachable

To ping range of IP’s:

$ fping -g 192.168.2.0/24

To list only unreachable hosts/IP’s

$ fping -q -u -f IPsFiles.txt

where -q is for Quiet mode and -u is to list only unreachable targets.

To list only reachable hots/IP’s

$ fping -q -a -f IPsFiles.txt

where -a is to list only alive hots.

iptables allow port for ip

 

To allow only an ip to access a port use following iptables rule

iptables -I INPUT -p tcp -m tcp -s 192.168.2.20 --dport 8080 -j ACCEPT

Above iptables rule will allow only 192.168.2.20 to access port 8080 and reject all other ip addresses.

Similarly we can give any other ip address and port combination.

Crontab every 30 seconds

 

To run a cron every 30 seconds check following example:

* * * * * /path/to/your/script arg1 arg2
* * * * * (sleep 30; /path/to/your/script arg1 arg2)

In above example both commands will start at 0th second of every minute, but the second command will sleep for 30 seconds and then start.

Vim – highlight search keyword

 

By default search keyword won’t be highlighted in vim with Ubuntu OS.

To highlight search keyword we need to set hlsearch flag in vimrc.

Open /etc/vim/vimrc with sudo and append following line in it:

set hlsearch

After that save & exit from vimrc file. This will enable search keyword highlight across all vim sessions.

If you want to enable highlighting only for current session run following command in vim after opening a file:

:set hlsearch

Username and password with wget/curl

 

To download a url with basic authentication we need to pass username & password.

To acheive this functionality with wget or curl observer following examples:

With curl:

$ curl -u 'username:password' 'http://www.example.com'

With wget:

$ wget --user='username' --password='password' 'http://www.example.com'

Wget with cookie:

Login to server & save cookie to a file:
$ wget --save-cookies cookiesFile.txt --post-data 'user=username&password=password' http://www.example.com/login.html

Download a page by using saved cookie file:
$ wget --load-cookies cookiesFile.txt -p http://www.example.com/somecontent.html

ssh disable warning messages – Linux/Ubuntu

To disable ssh warning message we need to add LogLevel to quiet in $HOME/.ssh/config file.

LogLevel=quiet

We can also diable warning messages with ssh command as shown below:

$ ssh -o LogLevel=quiet 192.168.1.10

With following example we can also disable Host Key Checking, set known hosts file to null and disable logging:

$ ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet 192.168.1.20