January 2009

Linux – Iftop

iftop command listens to network traffic on a named network interface, or on the first interface it can find which looks like an external interface if none is specified, and displays a table of current bandwidth usage by pairs of hosts. iftop is a perfect tool for remote Linux server over ssh session.

iftop must be run by the root or the user who has sufficient permissions to monitor all network traffic on the network interface.
Type iftop command at tge shell prompt to display traffic:

# iftop

However, iftop works best when you use filters. For example, if you want to find out how much bandwidth users are wasting or trying to figure out why the network is slow,

# iftop -f icmp

You can display or analyses packet flowing in and out of the network:

# iftop -F

Disable output for DNS traffic by using filter code such as:

# iftop -f 'not port domain'

iftop has many options read man page for further information.

Linux – Send mail from command line

The Linux command line can be very powerful once you know how to use it. You can parse data, monitor

One of major drawbacks of using the mail command is that it does not support the sending of attachments. mutt, on the other hand, does support it. I’ve found this feature particularly useful for scripts that generate non-textual reports or backups which are relatively small in size which I’d like to backup elsewhere. Of course, mutt allows you to do a lot more than just send attachments. It is a much more complete command line mail client than the “mail” command. Right now we’ll just explore the basic stuff we might need often. Here’s how you would attach a file to a mail:

# echo "Sending an attachment." | mutt -a backup.zip -s "attachment" leo@deepreflect.net

This command will send a mail to leo@deepreflect.net with the subject (-s) “attachment”, the body text “Sending an attachment.”, containing the attachment (-a) backup.zip. Like with the mail command you can use the “-c” option to mark a copy to another mail id.
Shell scripting:
Now, with the basics covered you can send mails from your shell scripts. Here’s a simple shell script that gives you a reading of the usage of space on your partitions and mails the data to you.

df -h | mail -s "disk space report" leo@deepreflect.net

Save these lines in a file on your Linux server and run it. You should receive a mail containing the results of the command. If, however, you need to send more data than just this you will need to write the data to a text file and enter it into the mail body while composing the mail. Here’s and example of a shell script that gets the disk usage as well as the memory usage, writes the data into a temporary file, and then enters it all into the body of the mail being sent out:

df -h > /tmp/mail_report.log
free -m >> /tmp/mail_report.log
mail -s "disk and RAM report" leo@deepreflect.net < /tmp/mail_report.log

Now here’s a more complicated problem. You have to take a backup of a few files and mail then out. First the directory to be mailed out is archived. Then it is sent as an email attachment using mutt. Here’s a script to do just that:

tar -zcf /tmp/backup.tar.gz /home/leo/files
echo | mutt -a -s /tmp/backup.tar.gz "daily backup of data" leo@deepreflect.net

The echo at the start of the last line adds a blank into the body of the mail being set out.

Debian – Service startup

Under Debian Linux startup files are stored in /etc/init.d/ directory and symbolic linked between /etc/rcX.d/ directory exists. Debian Linux uses System V initialization scripts to start services at boot time from /etc/rcX.d/ directory. Debian Linux comes with different utilities to remove unwanted startup file

Using rcconf:

This tool configures system services in connection with system runlevels. It turns on/off services using the scripts in /etc/init.d/. Rcconf works with System-V style runlevel configuration. It is a TUI(Text User Interface) frontend to the update-rc.d command.

Install rcconf in Debian:

#apt-get install rcconf

To start rconf, login as root user and type rcconf

# rcconf

Select the service you would like to enable or disable.

Using sysv-rc-conf:

sysv-rc-conf provides a terminal GUI for managing “/etc/rc{runlevel}.d/” symlinks. The interface comes in two different flavors, one that simply allows turning services on or off and another that allows for more fine tuned management of the symlinks. Unlike most runlevel config programs, you can edit startup scripts for any runlevel, not just your current one.

Install sysv-rc-conf in debian:

#apt-get install sysv-rc-conf

This will install sysv-rc-conf.Now you need to run the following command

# sysv-rc-conf

Select the service you would like to enable or disable.

Both sysv-rc-conf and rcconf are best tools to use on Remote Debian Linux or when GUI is not available

You can also use update-rc.d script as follows (update-rc.d removes any links in the /etc/rcX.d directories to the script /etc/init.d/service):

# update-rc.d -f {SERVICE-NAME} remove

For example to stop xinetd service you can type command as follows:

# update-rc.d -f xinetd remove

CentOS – Asterisk

Brevemente, come installare Asterisk su CentOS usando yum.
Partiamo dal indicare che ufficialmente CentOS nei sui repository non ha i pacchetti di asterisk, quindi è necessario utilizzarne degli altri, in particolare quelli di Trixbox che come ben sapere è basata su questa distribuzione.

Per primo, installare il plug-in che ci permette di gestire le priorità

[root@server ~]# yum install yum-priorities

Creare un file con il seguente contenuto e posizionarlo in /etc/yum.repos.d/ nominandolo con estensione .repo

name=Trixbox – Repo

A questo punto è necessario inserire il campo “priority=1” negli altri .repo presenti nella directory e procedere con l’installazione di asterisk soddisfando le dipendenze relative ad esso con il repository di Trixbox per evitare incompatibilità.