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.

Advertisements

OpenSSL is not properly installed on your system – Ubuntu

While trying to install some module I got error saying that “OpenSSL is not properly installed on your system ubuntu”.

I tried to reinstall this module after installing openssl, but no luck.

After debugging and exploring for a while I got to know that installing libssl-dev could resolve this issue, so I installed libssl-dev with following command:

$ sudo apt-get install libssl-dev

Now retried installation and it worked like charm.

Couchbase cli examples

 

Couchbase Server, originally known as Membase, is an open-source, distributed (shared-nothing architecture) NoSQL document-oriented database that is optimized for interactive applications.

By default couchbase-cli command is located at /opt/couchbase/bin/couchbase-cli.

Couchbase-cli examples:

To list servers:

$ /opt/couchbase/bin/couchbase-cli server-list -c hostname:8091 -u username -p password

To list buckets:

$ /opt/couchbase/bin/couchbase-cli bucket-list -c hostname:8091 -u username -p password

To get server info:

$ /opt/couchbase/bin/couchbase-cli server-info -c hostname:8091 -u username -p password

couchbase-cli help:

$ /opt/couchbase/bin/couchbase-cli help

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

Ansible – exclude host from playbook execution

By using –limit argument with ansible-playbook command we can exclude a host from playbook execution.
If hostname starts with “!” it will excluded from host execution.

Lets say if we want to exclude host1 and host2 from ansible-playbook execution use following command:

$ ansible-playbook --limit '!hoost1:!host2' yourPlaybook.yml

To exclude only host1 from execution use following command:

$ ansible-playbook --limit '!hoost1' yourPlaybook.yml

To execute only in host1 and host2 from execution use following command:

$ ansible-playbook --limit 'hoost1:host2' yourPlaybook.yml

To execute only in host1 use following command:

$ ansible-playbook --limit 'hoost1' yourPlaybook.yml

To exclude host1 and host2 from execution and allow execution only in host3:

$ ansible-playbook --limit '!hoost1:!host2:host3' yourPlaybook.yml

Python – check if ip is public or private

 

netaddr is a Python library for representing and manipulating network addresses.

Installing netaddr library:

Use any of following command to install netaddr library

$ sudo pip install netaddr
or
$ easy_install netaddr

Observe following example for more details:

>>> from netaddr import *
>>> IPAddress('74.125.236.194').is_private()
False
>>> IPAddress('192.168.1.10').is_private()
True
>>> IPAddress('127.0.0.1').is_loopback()
True

IPAddress(‘input ip’).is_private() will return true if the input ip address private, else it will return false.

Reference: Netaddr

Kibana connection failed elasticsearch 1.4

While trying to setup ELK(Elastic Search, Logstash and Kibana) I got an error saying “Connection Failed”

If you are suing elastic search version 1.4 or above this issue will occur.

To resolve it append following lines in elasticsearch.yml file(which is in config directory of elastic search):

http.cors.allow-origin: "/.*/"
http.cors.enabled: true

After adding above lines restart elasticsearch.

This should fix “Connection Failed” issue.

Ganglia – rrd remove negative spikes

 

By using rrdtool tune we can remove negative spikes from any rrd(round robin database).

Syntax:

$ rrdtool tune <RRD_FileName> --minimum ds-name:min

where, ds-name is the name you will use to reference this particular data source from an RRD.

min is minimum value, if we set minimum value of zero, it prevents negative rates.

In this example I am using test.rrd as my input rrd file.

To get ds-name first extract rrd file and with following command:

$ rrdtool dump test.rrd

Now look for following block in extracted data:

<ds>
<name> sum </name>
<type> GAUGE </type>
<minimal_heartbeat>240</minimal_heartbeat>
<min>NaN</min>
<max>NaN</max>

<!– PDP Status –>
<last_ds>0.600769042969</last_ds>
<value>0.0000000000e+00</value>
<unknown_sec> 0 </unknown_sec>
</ds>

In above output value between <name> and </name> is ds-name, so in above example sum is ds-name.

To remove negative run following commands:

#Set minimum value
$ rrdtool tune test.rrd --minimum sum:0
#Save new rrd
$ rrdtool dump test.rrd | rrdtool restore --range-check - test.rrd-fix
#Replace old rrd with new rrd
$ mv test.rrd-fix test.rrd

After running above 3 commands you wont see any negative values test.rrd

If the rrd is ganglia’s rrd you need to change permissions of rrd otherwise due to permissions new data won’t get updated to this rrd.

Use following command to change rrd permission:

$ chown nobody:root test.rrd