Archive for the ‘Command line’ Category

vim and PUTTY

Tuesday, September 16th, 2008

Most of “ux” users and administrators use remote terminal to connect to administrared machine.

One of the popular choises, minly because of it’s portability is PuTTy only putty.exe is needed and no installation is required. In addition it is free.

Downside is that sometimes there are problems with terminal emulation - not necessary coming from putty, but still annoying.

One of my problems is that when vim is in insert mode arrow keys do not work. For long time I was no able to find solution to the problem, but finally i found one. Just type this in your home folder:

echo syntax enable > ~/.vimrc

This did the trick for me. Hope it helps to you too.

How to have two IPs on one interface

Wednesday, February 27th, 2008

Recently I got into problem to assign 2 IPs on one physical NIC.

There was nothing mentioned in official documentation so I did some research and find the solution.

It is really simple if you are not afraid from command line and VI editor. Unfortunately I did not find a GUI.

Here it is:

  1. Go to command prompt
  2. Be sure that you are root. Otherwise type su - to become.
  3. Type - cd /etc/sysconfig/network-scripts/
  4. Then type ls to see the contents - you should have file ifcfg-eth0 if you have just one interface otherwise if you have multiple interfaces there you’ll find other files like ifcfg-eth1…n.
  5. Then we will copy the file to different name - cp ifcfg-eth0 ifcfg-eth0:0
  6. Next step is to edit newly created file and put the IP we needed.
  7. If needed repeat steps 5 and 6 with different numbers after”:” (1,2,…) to add additional addresses.
  8. If you issue ifconfig you will not see newly created interface, because it is no activated - you need to restart network /etc/init.d/network restart will do it for you.
  9. That’s it.

Comments are welcome.

Mass ping script

Friday, February 22nd, 2008

I needed to check multiple addresses for use.

I did not find any ready solution so I wrote a script.

I called it psweep.sh

Here is it(comments are welcomed):

#!/bin/bash
# Sweep ping
# 1-st arg ip 2-nd start 3-d end
#
# Written by Hristo Benev
#
# rev 0.3
#
for i in `seq $2 $3`; do
ping -c 1 -W 1 $1.$i >/dev/null 2>&1
#ping -c 1 -W 1 $1.$i
if [ $? == 0 ]; then
echo “host $1.$i is up”
else
echo “.”
fi
done
# changelog
# 0.3 added progress

RHEL/CentOS package xxxxx missing

Monday, July 30th, 2007

Often when installing 3-d party software in RHEL/CentOS or other yum capable Linux OS there is a message of missing libraries or packages.

How to fix it?

Here is the trick.

You can use yum package manager to search for missing pieces.

yum whatprovides <package name/library>

This command will search all configured repositories for package that provides it.
Another option is to search Internet.

TIP: For better stability install only packages in official repositories. OR ones that clearly specify that they work on your OS/version.

Shutdown IPtables firewall

Friday, July 27th, 2007

Sometimes in troubleshooting process is necessary to turn of firewall for a short period of time.

In Linux based OS usually IPtables is used as firewall. It runs as service and could be stopped, started or restarted. In addition the status could be checked.

Here is how to do it:

Command line

When in terminal type:

/etc/init.d/iptables
Usage: /etc/init.d/iptables {start|stop|restart|condrestart|status|panic|save}

Gives you hints how to use it.

Note that to execute any of actions you need administrative privileges - either login as root, “su -” or setup sudo.

another tool that is doing the same is

service iptables <command>

If you like GUI but use command prompt you can use:

system-config-securitylevel-tui

And you will have simple interface of configuring security - firewall and selinux

system-config-securitylevel-tui

GUI based

From GUI you can use the same tool just by removing -tui or go to System–>Administration –> Security level and firewall.

Another GUI frienly way is System–>Administration –> Services where you can do the same actions as from terminal.

TIP: Do not leave your system unprotected on Internet. Use cheap SOHO firewall in front of the system until IPtables is set up.

TIP: If you are newbie in firewall configuration use some third party tools as firestarter to guide you in your setup.

NOTE: Above steps are for RHEL (CentOS) compatible systems.

What could be better than top –> htop

Monday, July 16th, 2007

Thanks to Ubuntu tutorials I’ve realized that my lovely tool top has now better replacement htop.

Quick comparison:

Comparison between htop and top

  • In ‘htop’ you can scroll the list vertically and horizontally to see all processes and complete command lines.
  • In ‘top’ you are subject to a delay for each unassigned key you press (especially annoying when multi-key escape sequences are triggered by accident).
  • ‘htop’ starts faster (’top’ seems to collect data for a while before displaying anything).
  • In ‘htop’ you don’t need to type the process number to kill a process, in ‘top’ you do.
  • In ‘htop’ you don’t need to type the process number or the priority value to renice a process, in ‘top’ you do.
  • ‘htop’ supports mouse operation, ‘top’ doesn’t
  • ‘top’ is older, hence, more used and tested.

Fortunately it is available as binary package for RHEL 5 from rpmforge so the install was quick and painless:

yum install htop

Here is how it looks:

htop running

Default colors were not very appropriate for white background so I switched easily (F2-Setup->Colors) to mc colors.

How to unlock yourself - Linux screensaver

Friday, July 13th, 2007

Today I’ve accidentally locked myself with Linux screensaver.

How this happened?

I use English letters for my password, but when I’ve stepped back from my Linux workstation my keyboard group was with group different than English.

As result when I come back and tried to unlock myself I couldn’t enter the correct password.

Solutions:

1. First and simplest solution will be to kill X with Crtl+Alt+Backspace

2. Reboot the PC - Alt+Ctrl+Del

3. Try to fix it

Because I’ve had open and unsaved documents first 2 options will result loss of my work I’ve decided to go with third one.

How I did it:

A requirement is to have another PC and ssh access to main one.

1. Login via ssh to locked PC.

2. Start vnc server under your account

vncserver

Note you will need vnc server installed. How to do it is out of the scope - consult your documentation.

3. Open firewall ports required for VNC or simply shutdown firewall

/etc/init.d/iptables stop

4. On other PC start VNC client and connect to locked one

5. Start keyboard configuration

gnome-keyboard-properties

6. Remove all other layouts except English

7. Now you can return to locked PC and unlock it.

NOTE: This procedure was tested on LAN and CentOS 5.

Removing user in Linux

Thursday, July 5th, 2007

Today I removed the user in my Linux workstation.

Probably you will say that this is simple task just remove user home directory and his password, but appears that this is not.

First thing is that there is no single command that will do this task for you.

Let’s start:

1. Lock user - this is done with following command:

passwd -l <user_name>

This command will achieve it by changing the password to a value that cannot be matched by any possible encrypted value.

This command is usefull also for temporary disabling user account.

2. Search for and kill any user processes that still run

ps aux | grep -i ^<user_name>

kill -9 <PID number>

where <PID number> is the number in the column just after the user name.

3. Find all files that belong to this user

find / -user <user_name>|less

4. Decision time - decide do you want to keep those files or erase them. My suggestion is to backup them just in case.

5. List and remove any crontab jobs

List user cron jobs:

crontab -u <user_name -l

And if you see any entries remove them:

crontab -u <user_name> -r

6. Remove user from sudoers (if you use sudo)

visudo

7. Check any other applications as remote access, MySQL, Web App.
More extended howto

bash: /bin/rm: Argument list too long - How to fix it

Thursday, July 5th, 2007

Today I’ve decided to cleanup the hard drive on my Linux workstation and “surprisingly” found 8G of temporary files in one folder.

After quick review I’ve decided to erase them with rm command.

For my surprise when running the command:

/bin/rm *.tmp

I got following error message:

bash: /bin/rm: Argument list too long

Conclusion:Even rm command has his limits!

Solution: Get Plumber(Joking)
Actually only Pipe is needed.
By typing following command:

find . -name "*.tmp"|less

You will see list of the files and by replacing less with xargs /bin/rm those files will be erased. Can you skip previous step? Yes you can and it is not required, but you risk to erase a lot of data if you have syntax error.

find . -name "*.tmp"| xargs /bin/rm.

Depending on the number of files and your system speed after a while all files will be erased.

Done .