Μηνιαία αρχεία: Οκτώβριος 2011


How to change hostname (computer name) in Ubuntu (or Ubuntu Server)

If you do not have Unity/Gnome/KDE/or some other window manager, to do this you need to be familiar with a command line text editor like vi/emacs/nano.

To change your hostname simply edit /etc/hostname and restart the machine.

The /etc/hostname file should only contain the actual hostname, which makes editing it quite simple since you will just replace the hostname in the file with the one you want to assign.

NOTE: Elevated privileges are required, only administrators can edit this file.


bash: killall: command not found — A solution 1

On some systems like the JeOS version of Ubuntu, some commands that we consider trivial are not installed and usually there is an alternative that we are not aware of (e.g instead of nano there is vi).
In this case there is the pkill command that will send a specified signal (or SIGTERM if not specified) to all processes that match the name (more options are available).
For example instead of

killall badProcess

you can use

pkill badProcess

which is also pretty easy and straightforward.

Another solution,

would be of course to install it. If you have enough access you can install the package psmisc using the following command (in Ubuntu / Debian):

apt-get install psmisc

For RHEL – Red Hat / Fedora:

yum install psmisc

This package contains the following useful programs:

  • fuser – identifies what processes are using files.
  • killall – kills a process by its name, similar to a pkill Unices.
  • pstree – Shows currently running processes in a tree format.
  • peekfd – Peek at file descriptors of running processes.


How to call ‘top’ on a remote machine using ssh 8

Some times it is not straight forward to call some remote commands using ssh (example of syntax here). Commands like top will not execute as is because they need some environment variables modified due to their interactive nature.

Usage example of wrong remote call to top and its result:

ssh remoteMachine 'top'
TERM environment variable not set.

We cannot really describe all of the solutions available but since we are talking about top, we will present a very simple solution.
Luckily, top can be executed in batch mode, which is used for sending output from top to other programs or files by invoking the -b parameter and thus changing the command syntax to:

ssh remoteMachine 'top -b'

This will work just fine but give you a full page of results which might be too much info. To limit the results that you are receiving you can filter the top command results with other commands like head. In the following example we use head to limit the number of rows retrieved to 8, so that we get the system status and the most computational intensive command of our system.

ssh remoteMachine 'top -b | head -n 8'

Which will result to something like this:

top - 07:29:38 up 1:04, 0 users, load average: 2.85, 2.83, 2.24
Tasks: 62 total, 2 running, 60 sleeping, 0 stopped, 0 zombie
Cpu(s): 27.8%us, 0.4%sy, 0.0%ni, 71.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1022116k total, 68960k used, 953156k free, 4364k buffers
Swap: 3905532k total, 0k used, 3905532k free, 22776k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
842 userName 20 0 32212 1320 1120 R 188 0.1 46:51.91 application.binary