Friday 19 April 2013

Some Advance command in Linux

How to use 'ls' command to list only directories?

#ls -ld */
(or)
#ls -lp | grep ^dr
(or)  
#ls -pl | grep /$

Commands to get the PCI device information

# lspci
# lspci -v
# kudzu -p
# dmidecode --type 9
# lshw -short  (3rd party utility, package needs to be installed)

Automatically logout inactive SSH sessions

Typically in an Enterprise setup, we would see Users login from various terminals via SSH but never bother to disconnect the established session. This might cause a slight overload on the Network, since these Established sessions have to maintain their connections by sending Alive packets. So I guess it would be appropriate if we make these Users automatically Logout after a certain period of Inactivity (say 1 hour).

Solution 1:
Create a file called "autologout.sh" under /etc/profile.d with execute permission.
# touch /etc/profile.d/autologout.sh
# chmod 711 /etc/profile.d/autologout.sh
Add the following entries to it (Assuming we have to automatically Logout the users after 1 hour, which is 3600 seconds).

TMOUT=3600
readonly TMOUT
export TMOUT

Solution 2:
Enable the following directives in SSH config file (/etc/ssh/sshd_config) and reload the 'sshd' service.

ClientAliveInterval 3600
ClientAliveCountMax 0
# service sshd reload  (or)  # service sshd restart

Listing all Linux servers which are up in a network

Situation:
Suppose you want to find all the servers which are Up in Network or in a range of IPs.  We may need this information for trouble-shooting purpose like fixing IP conflicts or to get an idea about how many servers are online at a given point of time.


Solution:
# nmap -v -sP  <Network info>
The network info can be given as a whole network (say 10.10.22.0/24) or as a range (say 10.10.22.1-40).


Example:
[root@rahul-desktop ~]# nmap -v -sP 10.10.10.1-20     ß  Scans servers in the IP range of 10.10.10.1 to 10.10.10.20
Starting Nmap 5.21 ( http://nmap.org ) at 2013-01-31 17:45 IST
Initiating Ping Scan at 17:45
Scanning 20 hosts [2 ports/host]
Completed Ping Scan at 17:45, 1.30s elapsed (20 total hosts)
Initiating Parallel DNS resolution of 20 hosts. at 17:45
Completed Parallel DNS resolution of 20 hosts. at 17:45, 0.00s elapsed
Nmap scan report for tuxedo.integramicro.co.in (10.10.10.1)
Host is up (0.00036s latency).
Nmap scan report for 10.10.10.2 [host down]
Nmap scan report for 10.10.10.3 [host down]
Nmap scan report for 10.10.10.4 [host down]
Nmap scan report for 10.10.10.5 [host down]
Nmap scan report for 10.10.10.6 [host down]
Nmap scan report for 10.10.10.7 Host is up (0.00077s latency).
Nmap scan report for canon3300.rahul.co.in (10.10.10.8) Host is up (0.0024s latency).
Nmap scan report for pcc.rahul.co.in (10.10.10.9) Host is up (0.00063s latency).
Nmap scan report for backup.int.rahul.co.in (10.10.10.10) Host is up (0.00093s latency).
Nmap scan report for 10.10.10.19 Host is up (0.00072s latency).
Nmap done: 20 IP addresses (8 hosts up) scanned in 1.31 seconds
[root@rahul-desktop ~]#

No comments:

Post a Comment