Wednesday, January 11, 2012

Ping a list of servers

To do this, you need to put all the hosts that need to be checked in a file. For example, I put all my hosts in a file called ping_list:

$ cat ping_list
cat.myhost.net
dog.myhost.net
tiger.myhost.net
bird.myhost.net
There are a few ways to ping multiple hostnames, I'll list out what I have tried before:

1. Use nmap
$ nmap -sP -iL ping_list
Failed to resolve given hostname/IP: cat.myhost.net. Note that you can't use '/mask' AND '1-4,7,100-' style IP ranges
Failed to resolve given hostname/IP: dog.myhost.net. Note that you can't use '/mask' AND '1-4,7,100-' style IP ranges
Host 192.168.0.99 is up (0.00036s latency).
Host 192.168.0.100 is up (0.00061s latency).
where -sP is for ping test and -iL is for inputting from files.

2. One liner for loop
$ for i in `cat ping_list`; do ping -c1 $i; done
ping: unknown host cat.myhost.net
ping: unknown host dog.myhost.net
PING tiger.myhost.net (192.168.0.99) 56(84) bytes of data.

--- tiger.myhost.net ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

PING tiger.myhost.net (192.168.0.100) 56(84) bytes of data.

--- bird.myhost.net ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
I believe there are other tools or scripts beside those I listed above, but I always these 2 methods to ping multiple hosts. If you have other tools or script, please leave a comment.

Thanks

Tuesday, December 6, 2011

Store svn password

To store your cert and password, all you have to do is:

1. Go to .subversion in your home folder

$ cd ~/.subversion
2. Run below command. This command will add store-auth-creds = yes and store-passwords = yes to your bottom of config file
$ echo -e "store-auth-creds = yes\nstore-passwords = yes" >> config
3. Run any svn command, and choose p for permanent accept certificate, and yes for storing your password.

Now you won't be asked for svn password anymore.

Friday, November 25, 2011

Add file type swap to linux

To add swap to linux machine:

1. Create a swap file. Size depends on your preference. Let's say we want to create a swap file with 8GB size (1024 x 1024 x 8 = 8388608).

# dd if=/dev/zero of=/swapfile bs=1024 count=8388608
where if is source, of is output file for dd to write to which is /swapfile in this case, bs is read/write byte size at a time and count is number of blocks.

2. Once created, make it a swap file
# mkswap /swapfile
3. Activate your swap file
# swapon /swapfile
4. Check your newly created swap space using free or top
# free -m
or
# top
5. To make it appear even after reboot, put it into fstab
# echo "swapfile swap swap defaults 0 0" >> /etc/fstab
It will look like this:
# cat /etc/fstab 
...
/swapfile1 swap swap defaults 0 0
...

Tuesday, November 1, 2011

ssh forward tunnel

To make this happen, the command is like below:

$ ssh -L 10022:target.local:22 middle.local
where:
-L is for forward tunnel, 10022 is the port at localhost that we want to use, target.local is our target, 22 is the target's port that we want to forward and middle.local is our middleman server.

What the above command do is forwarding port 22 of target.local to port 10022 of localhost by using middle.local as a middleman. Once done, you can access port 22 of target.local just by SSHing into port 10022 in your localhost like below:
$ ssh localhost -p10022
and voila, you will be directed to target.local instead. This technique is useful when you have firewall blocking some ports, and you have server behind the firewall than can access those ports witth openssh installed.

Tuesday, October 25, 2011

Small script to test perl module

To test any perl module, just put below lines in a file, make it executable (chmod +x) and run it (./).

#!/usr/bin/perl
use DBD-Pg;
print "No errors!\n"
where DBD-Pg is example of perl module. This script will return "No errors!" if the module is available. If the module is not installed, an error like "Can't locate ...." will appear instead.