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.
$ 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.
$ jmap -heap PID
where PID is Java process id for which we want to get heap dump.
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
Starting Nmap 6.40 ( http://nmap.org ) at 2015-12-02 14:38 IST
Nmap scan report for http://www.google.com (184.108.40.206)
Host is up (0.085s latency).
Other addresses for http://www.google.com (not scanned): 220.127.116.11 18.104.22.168 22.214.171.124 126.96.36.199 188.8.131.52
rDNS record for 184.108.40.206: 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
To set crontab to run on every 5th, 15th, 25th, 35th, 45th, and 55th use following command:
5-55/10 * * * * command
This will execute your command on every 10th minute between 5 mins to 55 mins.
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
192.168.2.2 is alive
$ fping 192.168.2.22
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.
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.
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.
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:
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:
To download a url with basic authentication we need to pass username & password.
To acheive this functionality with wget or curl observer following examples:
$ curl -u 'username:password' 'http://www.example.com'
$ 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
To disable ssh warning message we need to add LogLevel to quiet in $HOME/.ssh/config file.
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
ssh-keygen command is used to remove offending key entries from .ssh/known_hosts
Syntax to remove offending key of a host:
$ ssh-keygen -R hostName/IP_Address
$ ssh-keygen -R test.example.com
Above example will remove ssh key associated with hostname test.example.com
$ ssh-keygen -R 192.168.1.10
This example will remove ssh key associated with IP Address 192.168.1.10