NMAP in Linux Examples

NMAP is one of the most important tool. Which checks which ports are open on a machine.
Some important to note about NMAP
  1. NMAP abbreviation is network mapper
  2. NMAP is used to scan ports on a machine, either local or remote machine (just you require ip/hostname to scan).
  3. NMAP is can be installed on windows, Sun Solaris machines too.
  4. NMAP can be used to scan large networks, remember I am saying large networks.
  5. NMAP can be used to get operating system details, uptime, software used for a service and its version no, vender of network card and uptime of that system too(Don’t worry we will see all these things in this post.
  6. Please do not try to use NMAP on machines which you don’t have permission.
  7. Can be used by hackers to scan for systems for venerability.
  8. Just a funny note : You can see this NMAP used by trinity in Matrix-II, when she tries to hack in to electric grid super computer.
Note : NMAP man pages one of the best man pages I have come across. It is explained in such a way that even new user can understand it easily and one more thing it is even having examples in to how to use NMAP in different situations, when you have time read it. You will get lots of information.

Example1 : Using NMAP in normal way, i.e. to scan a particular system for open ports
#nmap hostname

PS command: Memory and CPU Usage

we can use ps command to get the details of processes running on system in a efficient manner. 

This is useful when you are monitoring system processes.

# ps -eo s,pid,ppid,user,group,rss,vsz,pcpu,pmem,time,etime,tty,args
T     0     0     root     root    0    0  0.0  0.0       00:03 21-18:38:05 ?       sched
S     1     0     root     root 1920 2512  0.0  0.1       00:05 21-18:38:05 ?       /sbin/init
S     2     0     root     root    0    0  0.0  0.0       00:00 21-18:38:05 ?       pageout
S     3     0     root     root    0    0  0.3  0.0    01:22:51 21-18:38:05 ?       fsflush
S   203     1   daemon   daemon 2160 2456  0.0  0.1       00:00 21-18:37:49 ?       /usr/lib/nfs/lockd

Preparing reboot HPUX Server

Another nice article which I found on web

System administrators will often reboot their boxes because of certain need like patch installation and kernel parameter change. Below is a guide to properly shutdown and reboot the system.


1. Get important system information:

Common Information needed
# hostname
# date
# model
# uname -a
# uptime
# who -r

2. Gather filesystem information

Analyse HPUX crash dumps

Here the Quick Guide for How To Analyse HP-UX crash dumps.

You can to use the /usr/contrib/Q4/bin/q4 utility.
cd /var/adm/crash/crash.0
# /usr/contrib/Q4/bin/q4 -p . 
(note the "dot" at the end of the command)

At the 
q4> prompt,


q4> run Analyze AU > ana.out q4> run WhatHappened -HANG > what.out 

NOTE:  ctrl-c can interrupt these two commands,

which may take several minutes to process.

To exit

 q4:q4> exit

Login Script: Inventory Collection for domain computers

Here is the another script to collect the asset inventory of domain Computers over network. it will collect the Hardware and Software information of the Windows PC/Laptops which are logging into domain.

This is the easy to collect asset inventory of your networked Windows PC/Laptops. 

It will create two files for each computer: 

1 A file contains hardware details (Serial no, Model No, User, etc..)
2. Another file contains list of installed softwares on the computers

You can use txtcollector tool to merge all these files into one. you can easily import into excel and customize your report.

Place this script as your login script. or place this script in network drive and call it from your master login script.
Create a new group policy for this and assign to entire domain.

Change Default Location of My Documents Folder

Change the Default Location of the My Documents Folder

To change the default location of the My Documents folder, follow these steps:

  1. Click Start, and then point to My Documents.
  2. Right-click My Documents, and then click Properties.
  3. Click the Target tab.
  4. In the Target box, do one of the following:

    • Type the path to the folder location that you want, and then click OK. For example, D:\My Stuff

      If the folder does not exist, the 
      Create Message dialog box is displayed. ClickYes to create the folder, and then click OK
    • Click Move, click the folder in which to store your documents, and then click OKtwice.

How to check who has logged into your system

We often need to know who is currently logged on to a remote computer.
With native Windows commands only:

NBTSTAT -a remotecomputer | FIND "<03>" | FIND /I /V "remotecomputer"

The first name in the list usually is the logged on user (try playing with the NET NAME command to learn more about the names displayed by NBTSTAT).
This is the fastest way to find the logged on user name, and the results that you do get are correct, but NBTSTAT won't always return a user name, even when a user is logged on.

Using WMIC (Windows XP Professional and later):

WMIC /Node:remotecomputer ComputerSystem Get UserName

This is arguably the most reliable (native) command to find out who is logged on.

With the help of SysInternals' PSTools:

PSLOGGEDON -L \\remotecomputeror:

PSEXEC \\remotecomputer NET CONFIG WORKSTATION | FIND /I " name "or:

PSEXEC \\remotecomputer NET NAMEor:

PSEXEC \\remotecomputer NETSH DIAG SHOW COMPUTER /V | FIND /i "username"or:

FOR /F %%A IN ('REG Query \\remotecomputer\HKU ˆ| FINDSTR /R /B /C:"HKEY_USERS\\S-1-5-[0-9][0-9]-[0-9-]*$"') DO (
FOR /F "tokens=3 delims=\" %%B IN ('REG Query "\\remotecomputer\%%A\Volatile Environment"') DO (
SET LoggedinUser=%%B

NETSH and WMIC are for XP or later, and are the most reliable of all commands shown here.
WMIC requires WMI enabled remote computers and Windows XP on the administrator's computer; NETSH requires Windows XP on the remote computers.

PSLOGGEDON is a more accurate solution than NBTSTAT, but it will return the last logged on user if no one is currently logged on.

The NET and NBTSTAT commands show more or less identical results, but the NBTSTAT command is much faster.

The REG command is accurate, but may need to be modified depending on the version used. As displayed here, the code is written for REG.EXE 3.0 (XP).

If you want to search lots of computers for logged on users, I recommend you try NBTSTAT first (fast, but it won't always return the user name!), and only switch to NETSH, REG or WMIC (accurate) if NBTSTAT doesn't return a user name.

Scan and Configure New LUNS on Redhat Linux (RHEL)

Found another useful thing on the web. This is the quick guide to rescan and configure newly added LUNS in Linux. 

To configure the newly added LUNS on RHEL:

# ls /sys/class/fc_host
 host0  host1  host2  host3

 fdisk -l 2>/dev/null | egrep '^Disk' | egrep -v 'dm-' | wc -l

 echo "1" > /sys/class/fc_host/host0/issue_lip

 echo "- - -" > /sys/class/scsi_host/host0/scan

 echo "1" > /sys/class/fc_host/host1/issue_lip

 echo "- - -" > /sys/class/scsi_host/host1/scan

 echo "1" > /sys/class/fc_host/host2/issue_lip

 echo "- - -" > /sys/class/scsi_host/host2/scan

 echo "1" > /sys/class/fc_host/host3/issue_lip

 echo "- - -" > /sys/class/scsi_host/host3/scan

 cat /proc/scsi/scsi | egrep -i 'Host:' | wc -l

 fdisk -l 2>/dev/null | egrep '^Disk' | egrep -v 'dm-' | wc -l

Alternatively, we can
run the re-scan-scsi script.

To scan new LUNs on Linux operating system which is using QLogic driver 

You need to find out driver proc file /proc/scsi/qlaXXX. 

For example on my system it is /proc/scsi/qla2300/0 

Once file is identified you need to type following command (login as the root
# echo "scsi-qlascan" > /proc/scsi/qla2300/0
 # cat /proc/scsi/qla2300/0

Now use the script rescan-scsi-bus.sh new LUN as a device. Run script as follows:
# ./rescan-scsi-bus.sh -l -w

The output of ls -l /sys/block/*/device should give you an idea about how each device is connected to the system. 

Differentiate local storage from SAN LUN - Quick HOWTO

This is the nice information which i found on web. Its very useful. In many scenarios we want to Differentiate with local disks from SAN LUN. 

In the example below orange is a virtual disk on an internal RAID controller, green is a CD-ROM connected via an IDE controller, and the rest are SAN-connected SCSI disks where "hostN" refers to the instance of the Host Bus Adapter they are connected to.

 # ls -l /sys/block/*/device

lrwxrwxrwx  1 root root 0 Sep 19 02:11 /sys/block/cciss!c0d0/device -> ../../devices/pci0000:00/0000:00:04.0/0000:0d:00.0/disk0 
lrwxrwxrwx  1 root root 0 Sep 19 02:11 /sys/block/hda/device -> ../../devices/pci0000:00/0000:00:1f.1/ide0/0.0
lrwxrwxrwx  1 root root 0 Sep 18 14:58 /sys/block/sda/device -> ../../devices/pci0000:00/0000:00:02.0/0000:13:00.0/host0/target0:0:0/0:0:0:0  
lrwxrwxrwx  1 root root 0 Sep 18 14:58 /sys/block/sdb/device -> ../../devices/pci0000:00/0000:00:02.0/0000:13:00.0/host0/target0:0:0/0:0:0:1 
lrwxrwxrwx  1 root root 0 Sep 18 14:58 /sys/block/sdc/device -> ../../devices/pci0000:00/0000:00:02.0/0000:13:00.0/host0/target0:0:0/0:0:0:64  
lrwxrwxrwx  1 root root 0 Sep 18 14:58 /sys/block/sdd/device -> ../../devices/pci0000:00/0000:00:02.0/0000:13:00.0/host0/target0:0:0/0:0:0:120  ...

Microsoft Softwares for free to Students

It's about giving students Microsoft professional tools at no charge.

The DreamSpark program provides professional technology tools free to all verifiable students across India. 

Microsoft is able to provide this offer securely to students by leveraging the existing infrastructure established by universities across the country and to enable friction free student access to genuine software "at no cost"!

Through this endeavor Microsoft aims to empower students with the tools they need during their academic experience and the skills they will need after graduation.
You need to login and verify your student identity to download these free softwares

For More details,



Linux Important Files and Summary

Linux Important File Summary

at.allow, at.deny
If at.allow exists, then only the user accounts listed in the file may use the at or batch commands. If at.deny exists, then any user account listed in the file may not use the at or batch commands.
Shell script to clean up any personalized environment settings during logout.
Shell script to set personalized environment settings for each login.
Shell script to set personalized functions and aliases for each newly created shell or subshell.
Shell script to set system-wide functions and aliases. Usually called by /home/<user>/.bashrc.
cron.allow, cron.deny
If cron.allow exists, then only the user accounts listed in the file may use the crontab command. If cron.deny exists, then any user account listed in the file may not use the crontab command.



1. First create a bootable logical volume disk. 
#pvcreate –B /dev/rdsk/c0t1d0  

2. Add the PV to vg00. 
#vgextend /dev/vg00 /dev/dsk/c0t1d0

3. Place Boot Utilities on disk:   
#mkboot /dev/rdsk/c0t1d0 

4. Add the AUTO File to the LIF area:  
#mkboot –a “hpux –lq (;0)/stand/vmunix” /dev/rdsk/devicefile 



1. First create a bootable logical volume disk. 

2. Mirror the root logical volume to new disk: 
#lvextend –m 1 /dev/vg00/lvol1 /dev/dsk/c0t1d0 

3. Mirror the Primary Swap area: 
Lvextend –m 1 /dev/vg00/prswaplv /dev/dsk/c0t1d0 

4. Verify the LVM was updated: 
#lvlnboot –v 


Mirrors are created and broken from an lvol level. Remember this. If you want to break the mirror for /dev/vg00/lvol1 which may be mounted at / do the following: 

#lvsplit /dev/vg00/lvol1      
This will by default create a

Mirroring rootvg in AIX

Use the following steps to mirror an AIX rootvg.

Make sure you have an empty disk, in this example its hdisk2
  • Add the disk to the vg via "extendvg rootvg hdisk2
  • Mirror the vg via: "mirrorvg rootvg"
  • Adapt the bootlist to add the current disk, the system will then fail to boot into hdisk2  when hdisk0 fails during startup
    • Type "bootlist -o -m normal"
      • this will list currently 1 disk, in this exmaple hdisk0
    • Type "bootlist -m normal hdisk0 hdisk2"
  • Run a bosboot on both new disks, this will install all software needed for boot on the disk
    • bosboot -ad hdisk0
    • bosboot -ad hdisk2
  • Thats all you are done :)


If you want to extend /usr from 300MB to 600MB, and there is available space, do the following:
1. Determine lvol # of /usr. Type:


Make note of the lvol that is mounted to /usr.

2. Increase lvol6 to 600MB:  
/sbin/lvextend -L 600 /dev/vg00/lvol6 (-L is new size in MB)

3. Extend the file system using OnlineJFS:         
#/sbin/fsadm –F vxfs –b 600m /usr (m is for MB)

In this example you want to extend /usr from 300MB to 600MB but there is no available space in the volume group that the /usr filesystem is on. In this case you would

Runlevel Service Management in Linux

  • We can indicate desired runlevels for each services in Linux
  • Services are located in: /etc/init.d

1. /usr/sbin/ntsysv:

1. ntsysv - manages services in the current run-level
2. ntsysv 35 - manages services for run-levels 3 & 5

Note: ntsysv nor chkconfig starts|stops services

2. Chkconfig

1. chkconfig --list ntpd - returns run-level environment for 'ntpd'
Note: items listed as 'off' have K (kill) scripts Note: items listed as 'on' have S (start) scripts
2. chkconfig --level 3 ntpd off - creates a K(kill) script in run-level 3

AWK and SED Command Examples in Linux – Quick HOWTO

AWK Features:

1. Field/Column processor
2. Supports egrep-compatible (POSIX) RegExes
3. Can return full lines like grep
4. Awk runs 3 steps:
a. BEGIN - optional 
b. Body, where the main action(s) take place
c. END - optional
5. Multiple body actions can be executed by separating them using semicolons. e.g. '{ print $1; print $2 }'
6. Awk, auto-loops through input stream, regardless of the source of the stream. e.g. STDIN, Pipe, File

1. awk '/optional_match/ { action }' file_name | Pipe
2. awk '{ print $1 }' grep1.txt