Pages

Sunday, April 16, 2017

What is the use of nsswitch.conf

nsswitch - Name Service Switch configuration file (nsswitch.conf)

The Name Service Switch configuration file (/etc/nsswitch.conf), is used by the GNU C Specifies the method to use and the order in which to use them when looking  for a users passwords, hosts ip and group. you can also specify what action the system takes based on whether a method works or fails.

Each category of information is identified by a database name. The file is plain ASCII text, with columns separated by spaces or tab characters.  The first column specifies the database name.  The remaining columns describe the order of sources to query and a limited set of actions that can be performed by lookup result.  

/etc/nsswitch.conf covers way more than host names: it also covers the resolution of mail aliases, user and group names, network protocol, service and segment names and others.

Syntax of file : info: method [[action]] [method] action

Some Sample entries from conf file

passwd:     files
shadow:     files
group:      files
hosts:      files dns
#hosts:     db files nisplus nis dns

Valid entries include:

nisplus  = Use NIS+ (NIS version 3)
nis = Use NIS (NIS version 2), also called YP
dns = Use DNS (Domain Name Service)
files = Use the local files
db =  Use the local database (.db) files
compat =  Use NIS on compat mode
hesiod =   Use Hesiod for user lookups
[NOTFOUND=return] Stop searching if not found so far

To use db, put the "db" in front of "files" for entries you want to be

[STATUS=ACTION] , [!STATUS=ACTION]

where
STATUS => success | notfound | unavail | tryagain
ACTION => return | continue

The ! negates the test, matching all possible results except the one specified. The case of the keywords is not significant.

The STATUS value can be one of:

success - No error occurred and the requested entry is returned. The default action for this condition is "return".

notfound - The lookup succeeded, but the requested entry was not found. The default action for this condition is "continue".

unavail - The service is permanently unavailable. This can mean either that the required file cannot be read, or, for network services, that the server is not available or does not allow queries. The default action for this condition is "continue".

tryagain - The service is temporarily unavailable. This could mean a file is locked or a server currently cannot accept more connections. The default action for this condition is "continue".

The ACTION value can be one of:

return - Return a result now. Do not call any further lookup functions. However, for compatibility reasons, if this is the selected action for the group database and the notfound status, and the configuration file does not contain the initgroups line, the next lookup function is always called, without affecting the search result.

The entry '[NOTFOUND=return]' means that the search for an  entry should stop if the search in the previous entry turned  up nothing. Note that if the search failed due to some other reason  (like no NIS server responding) then the search continues with the  next entry.

continue - Call the next lookup function.

What is the difference between /etc/host.conf and /etc/nsswitch.conf

In simplet terms, GNU C Library 2.x uses /etc/nsswitch.conf and older versions use /etc/hosts.conf.

To Check the GNU lib C Version, use ldd -version

[user@XXXX]# ldd --version
ldd (GNU libc) 2.12

What is Nice and Renice

With the help of Nice and Renice we can alter the priority of a process. Users other than the root can only alter the priority of the processes which they own, within the range 0 to 20. root user can alter the priority of any process and set the priority to any value in the range -20 to +20.  In Simple anything negative will make things go very fast.

To check the nice value of running process execute

# ps -al - Nice value is listed under the column heading "NI”

Values of Nice and Renice : -20 to 19 and Default Value is 0. 

Least nice value : (-20) is highest priority 

Most nice value : (19) is lowest priority.

Launching a program with Priority 

nice -n <nice value> <command/Process>

Changing the priority of a running process

(i) To change the nice value for a particular process.

renice -n <nice value> -P <PID>

(ii) To change the nice value for all the process owned by a particular user/group.

# renice -n <nice value> -U <UserName>
# renice -n <nice value> -g <GroupName>

How to check the nice value of  a process

# ps -eo pid,user,nice,command (or) top

In top command filed NI will give the niceness value.

Saturday, April 15, 2017

Shift Command

Shift Command is basically used to move the command line arguments to left. In shell scripting the maximum no. of command line parameters becomes 9. If we want to get more than 9 parameters we use the shift command.

[user@ XXXXX]# cat myscript.sh
#!/bin/bash
echo "Input: $@"
shift 3
echo "After shift: $@"

[user@ XXXXX]# sh myscript.sh one two three four five six

Input: one two three four five six
After shift: four five six

Difference Between TCP and UDP

The essential difference is that UDP is "fire and forget" (and like a bullet, if it misses it doesn't tell you...) - there's no acknowledgement of UDP traffic from the receiver built into the protocol, no flow-control, error-correction or windowing (packet segmentation/sequencing/reassembly/size-negotiation) - all these are parts of the TCP protocol specification, there are clues in the names - User Datagram Protocol (like a telegram, you send it and *may* get a reply depending on what the destination does but no guarantee) and Transmission Control Protocol (like a phone call, there's an end-to-end transmission path in both directions and negotiations between end-points, it's "connection oriented" where UDP is "connectionless").



Much of the activity in a TCP connection is needed because of the non-deterministic, unreliable nature of the Datalink layer - much of Ethernet has been handed down from the Alohanet (networking over a single radio channel with collision avoidance by carrier sensing), and until the advent of store-and-forward switches and routers there was no guarantee of delivery. Things are better now, but UDP is still an inferior choice if reliability matters! 

Image2001.gif

Handshake SYN, SYN-ACK, ACK No handshake (connectionless protocol)
Header SizeTCP header size is 20 bytesUDP Header size is 8 bytes.


UDP packets can not be greater then 512 bytes.

find command with examples

find will be used to search files and folders. Below are some of the additional options of find command 

1) Maxdepth and Mindepth 

# -maxdepth n  - will search only to n levels

-mindept n - will start search from level n through remainder of direcoty eg : 3 will begin search. level2 and continue to end. if the folder has only two sub directories then we wont get result

2)
Ignore some directories while searching in a path

prune option will be used to ignore the directory while searching in a path.


find [path] - prune -o [your usual condition] 

find / -path /etc -prune -o  -name '*conf'

for example if you want to avoid searching .conf files in etc but exculde ssh directory then the condtion will be like

To Ignore multiple directories while searching

find . -type d \(-path dir 1 -o -path dir 2 -o -path dir 3\) -prue -o -print 

1) grep in sub directories on files which has space in name's 

We can use getfacl and setfacl to backup and restore permission. Below is the example.


# find . -name "*.yaml"  -print0 | xargs -0  grep -i "orabat"

To find empty files and folders


# find / -empty -type f
# find / -empty  -type d

To find  files/directories of above/below particular size

# find / -type f -size +100M
# find / -type f -size -100M

To find files owned by particular user/group

# find / -UID 510
# find / -GID 510
# find / -nouser
# find / -nogroup

print 0 option
find -print0 True; print the full file name on the standard output, followed by a null character (instead of the newline character that -print uses).  This allows file names that contain newlines or  other  types of white space to be correctly interpreted by programs that process the find output.  This option corresponds to the -0 option of xargs.

print0 will print  the output in a single line

-print0 True; print the full file name on the standard output, followed by a null character (instead of the newline character that -print uses).  This allows file names that contain newlines or  other  types of white space to be correctly interpreted by programs that process the find output.  This option corresponds to the -0 option of xargs.