Posts

Showing posts with the label Unix

A rarely used but very useful option in grep

I usually do a lot of log analysis. I search for patterns in multiple files in multiple hosts. Then I collate the result and do processing on the result lines. A sample output looks like: /tmp/input1.txt: line containing pattern /tmp/input2.txt: another line containing pattern  As it turns out, I don't need the file names in the grep result. I always used to remove the file name prefixes using a Perl one-liner. Silly me! I was pretty sure that this was a common problem and it must have been solved already. When I referred to the man page of grep , I came across this gem: -h . If you specify this option, grep will not prefix each line with a the file name. There is also -H option which will prefix each line with a filename even if you are searching in only one file.

dhclient - Obtaining IP address dynamically

Whenever you want to obtain a dynamic IP address for your Linux/Unix machine from a DHCP server, you should use dhclient utility. Both DHCP request and responses are UDP requests. If you use a sniffer to identify the pattern of the request responses, the following is what you might see. The following was taken from dhclient running in FreeBSD 6.1. Len SrcIP SrcMACAddr DestIP DestMACAddr Protocol 342 0.0.0.0 00:0c:29:c1:13:81 255.255.255.255 ff:ff:ff:ff:ff:ff UDP 62 192.168.49.254 00:50:56:ef:75:a8 192.168.49.128 ff:ff:ff:ff:ff:ff ICMP ping request 342 192.168.49.254 00:50:56:ef:75:a8 192.168.49.128 00:0c:29:c1:13:81 UDP 60 192.168.49.128 00:0c:29:c1:13:81 ff:ff:ff:ff:ff:ff ARP request If you observe the source and destination (IP, MACAddr) patterns, it is easy to appreciate what happens. Here is what happens: A DHCP request is sent on the network. Both destination MACAddr and IPAddr are broadcast addresses. The DHCP server chooses and IP ...

Issue of CRLF chars

I faced a very weird problem while I was trying to find log, check out or update files from the CVS repository. The following error message was flashed on the screen: [myuserid@localhost java]$ cvs log . myuserid@mycvshost's password: cvs-1.11.17_p2 log: Logging . : No such file or directoryopen directory /cvsroot/my/repository cvs-1.11.17_p2 log: skipping directory myuserid@mycvshost's password: " but pserver says "/cvsroot/my/repository"/my/repository I could sense that this might be related to some CRLF (Carriage Return-Line Feed) issue, as all the error lines seem to be starting with what look like end of string delimiters (":" or "\""). So to further clarify my doubt I redirected the output to a file and this is the exact error message I was getting: cvs-1.11.17_p2 log: Logging . cvs-1.11.17_p2 log: cannot open directory /cvsroot/my/repository^M: No such file or directory cvs-1.11.17_p2 log: skipping directory Protocol error: Root s...