Sunday, April 19, 2009

Just opened binary file in vi !!!!!!!

By mistake,you have just opened one binary file in vi and screen continues to scroll. You may use CTRL + C to stop that. But now,junk characters are appearing in prompt. You are not able to read anything.Try reset command. It will Reset scrambled screen.


To test this command try opening some binary file and issue reset command after stopping scrolling by pressing CTRL + C.

How to see what others are doing in real time ?

There are some situation when you are only interested in knowing what others are doing.
Let say two guys are trying to fix a server and as a supervisor, you are interested in knowing how they are doing in real time.

You may do this using script command. Let say person is logged in and his terminal type is pts/0. Running "w" tells this.

script -f /dev/pts/0

This tool is good for learning from team member's skill.

Why dont you save your command and its output ?

Lets say you are working on a known issue and you need to document the commands and their result.
You may use script command to capture various commands and its output.

How to use script

$script FILE-NAME

This command will open new shell. Now what ever command you issue,along with its output will be logged into FILE-NAME. Once you are done,press "CTRL-D" and you are out of screen command.

Although this command is very simple but it helps to document things.

lsof can be used in many ways for troubleshooting purposes

lsof is a very useful command. Is shows various opened files. You may use lsof with specific port,pid or process.When used in correct context,it will save your life in difficult troubleshooting sessions.

Suppose you want to see what are the various services running in you server. I know you will say netstat. But you may also use lsof -i -n.

lsof -i -n

-n for overriding dns resolution
Lets discuss some of other cases too.
lsof -i:389

Port 389 is used by ldap by default.
This will show all the services on this port. It will also show connection status too.
lsof -i:143 -n

-n will give ip address instead of fqdn
lsof -p:1234

There were some situation when some stale processes were hindering new processes to spawn. This switch will display all the files,connections,sockets opened by it.
We can confirm if the particular process is stale(before kill -9)
-c process_name
lsof -c dhcpd

This switch will show all the files(connection status,type) and many other regular info of this process.

what are the various resources a process is utilizing ?

There was one particular incidence when i am making changes in some conf file but its not taking effect.There were some cases when i am expecting spool directory's path in some other location but postfix is picking up some other location.
In nutshell, we want to see what are the files a particular daemon is using or opening or referring.
Lets be more specific.As i mainly deal with postfix, there are mainly two conf files, master.conf and main.conf. We are interested in knowing what are the files master process is using, i will issue following command to get this info

lsof -c master

it will show all the files,sockets,tcp connections attached to this process.

You may use other processes too to track them down.

Very useful in case you are running out of ideas what next to do if correct thing in correct place( as you think) is not taking place.

I was trying to clear spool directory but master was using different location. I was expecting it to be where it should be(during build i specified) but default postfix installation in OS was forcing different spool location(during booting).

Whole story is too big to mention here. Not in context too.

How to log output of remote ssh session ?

There are many instances when you are going to ssh to remote server for troubleshooting and data gathering purposes and you want to save those data in your computer.
There is a less frequently but useful "tee" command which could be used to log all output in a remote ssh session. What it will actually do is that it will generate one file which will capture all the commands as well as their output.

ssh | tee /path/of/log/file

This command is very useful for troubleshooting purposes.