Mar
26
Posted on 26-03-2008
Filed Under (Linux Networking) by Ravi Bhure

Introduction

MRTG is wonderful tool. You can use it to monitor traffic on your router or leased server located at remote IDC. Since it is written in Perl and some code in C language, it is portable and high performance tool.

What is MRTG?

As explained in official mrtg(1) man page “The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network-links. MRTG generates HTML pages containing GIF images which provide a LIVE visual representation of this traffic. Please note following discussion based upon Red Hat Linux Enterprise version 4.

What is SNMP and why should I care?

SNMP is Simple Network Management Protocol. It is use to manage IP network devices such as servers, routers, switches etc. Administrator can find or manage network performance, solve problem or even optimize it further. For more information on official UNIX/Linux SNMP please see UCD-SNMP/NET-SNMP Tutorials and an excellent resource at Snmplink.org

Assumptions

These installation instructions assume you have:

  • Linux distribution
  • You would like to perform MRTG and snmp binary installation using rpm. If you are looking for source installation then visit author’s web site here. This page has an excellent information (systematically) to install it from source.
  • Required RPMs
    • mrtg
    • snmp
    • snmp-utils
  • Installations were tested on Red Hat Enterprise Linux version 4 & 5.

Configuration

Make sure snmp server is working. Without proper working snmp server, mrtg will not work. Therefore, first step is make sure snmp up and running. Following steps will take you gradually to configure it.

Configure SNMP

(1) Edit file /etc/snmp/snmpd.conf using text editor:

# vi /etc/snmp/snmpd.conf

Change/Modify line(s) as follows:

Find following Line:

com2sec notConfigUser  default       public

Replace with (make sure you replace 192.168.0.0/24 replace with your network IPs) following lines:

com2sec local     localhost           public
com2sec mynetwork 192.168.0.0/24      public

Scroll down bit and change:

Find Lines:

group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser

Replace with:

group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
group MyROGroup v1         mynetwork
group MyROGroup v2c        mynetwork
group MyROGroup usm        mynetwork

Again scroll down bit and locate following line:

Find line:

view    systemview     included      system

Replace with:

view all    included  .1                               80

Again scroll down bit and change:

Find line:

access  notConfigGroup ""      any       noauth    exact  systemview none none

Replace with:

access MyROGroup ""      any       noauth    exact  all    none   none

access MyRWGroup ""      any       noauth    exact  all    all    none

Scroll down bit and change:

Find lines:

syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root  (configure /etc/snmp/snmp.local.conf)

Replace with (make sure you supply appropriate values):

syslocation Linux (RH4_UP4), Ravi’s Linux Router.

syscontact Ravi Bhure <ravi@indianGNU.org>
 

Start your snmp server and test it:

(a) Make sure when linux comes up snmpd always starts:

 # chkconfig snmpd on

(b) Make sure service start whenever Linux comes up (after reboot):

 # service snmpd start

(c) Finally test your snmp server:

# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

Install mrtg if not installed

Mrtg software may install during initial installation; you can verify if MRTG installed or not with following RPM command:

rpm -qa | grep mrtg

Use rpmfind.net to find MRTG rpm or up2date command to install MRTG software:

# up2date -v -i mrtg

Fedora Linux user can use yum command as follows to install MRTG:

# yum install mrtg

Commands to Configure mrtg

(a) Create document root to store mrtg graphs/html pages:

# mkdir -p /var/www/html/mymrtg/

(b) Run any one of the following cfgmaker command to create mrtg configuration file:

#cfgmaker --global 'WorkDir: /var/www/html/mymrtg' --output /etc/mrtg/mymrtg.cfg public@localhost

OR (make sure your FQDN resolves, in following example i’m using example.com which is my router FQDN address)

# cfgmaker --global 'WorkDir: /var/www/html/mymrtg' --output /etc/mrtg/mymrtg1.cfg public@example.com

(c) Create default index page for your MRTG configuration:

# indexmaker --output=/var/www/html/mymrtg/index.html /etc/mrtg/mymrtg1.cfg

(d) Copy all tiny png files to your mrtg path:

# cp -av /var/www/mrtg/*.png /var/www/html/mymrtg/
 

(e) Create /etc/httpd/conf.d/mymrtg.conf and write just one line

Alias /mymrtg /var/www/mymrtg

Save and exit.

First test run of mrtg

(a) Run mrtg command from command line with your configuration file:

# mrtg /etc/mrtg/mymrtg1.cfg

Note: You may get few warning message for first time; ignore them.

(b) Fire your favorite web browser (like FireFox 😀 ) and type url http://www.your.com/mymrtg/ or http://your-ip/mymrtg/

Create crontab entry so that mrtg graph / images get generated every 5 minutes

(a) Login as a root user or login as a mrtg user and type following command:

# crontab -e

(b) Add mrtg cron job entry to configuration file (append following line to it):

*/5 * * * * /usr/bin/mrtg /etc/mrtg/mymrtg1.cfg --logging /var/log/mrtg.log

Save file and you are done with MRTG config issues 🙂

NOw NJoy MRTG.

Thanks

Ravi

(3) Comments    Read More   
Mar
25
Posted on 25-03-2008
Filed Under (Shell scripting) by Ravi Bhure

Few months ago I wrote a script that mail to admin for low disk space Shell script to monitor or watch the disk space but now here we improved the script in few better steps.

#!/bin/bash

# Shell script to monitor or watch the low-disk space
# It will send an email to $ADMIN, if the (free avilable) percentage
# of space is >= 90%
# ————————————————————————-
# Linux shell script to watch disk space (should work on other UNIX oses )
# SEE URL: http://www.indiangnu.org
# set admin email so that you can get email
# set alert level 90% is default

PATHS=”/”

AWK=/bin/awk

DU=”/usr/bin/du -ks”

GREP=/bin/grep

DF=”/bin/df -k”

TR=/usr/bin/tr

SED=/bin/sed

CAT=/bin/cat

MAILFILE=/tmp/mailviews$$

MAILER=/bin/mail

mailto=”ravi@indianGNU.org”

for path in $PATHS

do

DISK_AVAIL=`$DF $path | $GREP -v “Filesystem” | $AWK ‘{print $5}’|$SED ‘s/%//g’`

if [ $DISK_AVAIL -gt 90 ];then

echo “Please clean up your stuff \n\n” > $MAILFILE

$CAT $MAILFILE | $MAILER -s “Clean up stuff” $mailto

fi

done

Thanks

RAvi

(2) Comments    Read More   
Mar
17
Posted on 17-03-2008
Filed Under (Linux commands) by Ravi Bhure

The write command enables you to write an actual message on the other terminal online. You have to issue the write command with the login ID of the user with whom you want to communicate. The write command informs the user at the other end that there is a message from another user. write pastes that message onto the other user’s terminal if their terminal’s write permissions are set. Even if they are in the middle of an edit session, write overwrites whatever is on the screen. The edit session contents are not corrupted; you can restore the original screen on most editors with Ctrl-L.

write is mostly used for one-way communication, but you can have an actual conversation as well.

example: write user [ttyname]

With Regards,

Ravi Bhure

(1) Comment    Read More   
Mar
14
Posted on 14-03-2008
Filed Under (Shell scripting) by Arun Bagul

Introduction-

The UNIX/Linux Administrator or programmers have difficulties to solve this kind of quiries. Many times we need to rename perticular files within the given directories for example
we have to rename all the text file to conf file ie *.txt file to *.conf file….

We can use Pattern matching with String Operators in Shell scripting —

root@arunbagul:/home/arun/templates# touch main.txt data.txt readme.txt sample.txt demo.txt
root@arunbagul:/home/arun/templates# ls
data.txt demo.txt main.txt readme.txt sample.txt
root@arunbagul:/home/arun/templates#
Suppose you have thousands of *.txt files in given directory –

It is very difficult to rename this files to some other extension like *.conf
Take the above case and we will try to rename *.txt file by using shell script

root@arunbagul:/home/arun# ls -l /home/arun/templates/
total 0
-rw-r–r– 1 root root 0 2008-03-13 16:29 apache.conf
-rw-r–r– 1 root root 0 2008-03-14 02:50 data.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 demo.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 main.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 readme.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 sample.txt
root@arunbagul:/home/arun#

** In above “/home/arun/templates/” directory there are few *.txt files and
we will rename this files as *.conf files. There is apache.conf file, which will not rename.

root@arunbagul:/home/arun# ll /home/arun/templates/
total 0
-rw-r–r– 1 root root 0 2008-03-13 16:29 apache.conf
-rw-r–r– 1 root root 0 2008-03-14 02:50 data.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 demo.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 main.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 readme.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 sample.txt
root@arunbagul:/home/arun#

Now run our command as given below..

root@arunbagul:/home/arun# ./rename.sh /home/arun/templates txt conf
Rename all the *.txt files as .conf files…
Directory is = /home/arun/templates
renaminng /home/arun/templates/main.txt to /home/arun/templates/main.conf
renaminng /home/arun/templates/apache.txt to /home/arun/templates/apache.conf
renaminng /home/arun/templates/sample.txt to /home/arun/templates/sample.conf
renaminng /home/arun/templates/demo.txt to /home/arun/templates/demo.conf
renaminng /home/arun/templates/data.txt to /home/arun/templates/data.conf
renaminng /home/arun/templates/readme.txt to /home/arun/templates/readme.conf
root@arunbagul:/home/arun#

root@arunbagul:/home/arun# ls -l /home/arun/templates/
total 0
-rw-r–r– 1 root root 0 2008-03-13 16:29 apache.conf
-rw-r–r– 1 root root 0 2008-03-14 02:50 data.conf
-rw-r–r– 1 root root 0 2008-03-14 02:50 demo.conf
-rw-r–r– 1 root root 0 2008-03-14 02:50 main.conf
-rw-r–r– 1 root root 0 2008-03-14 02:50 readme.conf
-rw-r–r– 1 root root 0 2008-03-14 02:50 sample.conf
root@arunbagul:/home/arun#

Supose After some time we want to revert back!! ie want to rename *.conf file as *.
Run the above command and change the extension on command line as shown below

root@arunbagul:/home/arun# ./rename.sh /home/arun/templates/ conf txt
Rename all the *.conf files as .txt files…
Directory is = /home/arun/templates
renaminng /home/arun/templates/demo.conf to /home/arun/templates/demo.txt
renaminng /home/arun/templates/apache.conf to /home/arun/templates/apache.txt
renaminng /home/arun/templates/readme.conf to /home/arun/templates/readme.txt
renaminng /home/arun/templates/data.conf to /home/arun/templates/data.txt
renaminng /home/arun/templates/main.conf to /home/arun/templates/main.txt
renaminng /home/arun/templates/sample.conf to /home/arun/templates/sample.txt
root@arunbagul:/home/arun#

root@arunbagul:/home/arun# ll /home/arun/templates/
total 0
-rw-r–r– 1 root root 0 2008-03-13 16:29 apache.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 data.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 demo.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 main.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 readme.txt
-rw-r–r– 1 root root 0 2008-03-14 02:50 sample.txt
root@arunbagul:/home/arun#

Want to see the code ?

root@arunbagul:/home/arun# cat /home/arun/rename.sh
#! /bin/bash

path=$1
old_extension=$2
new_extension=$3
echo “Rename all the *.$old_extension files as .$new_extension files…”

#remove the trailing ‘/’ from end of the path
path=”${path%/}”
echo “Directory is = $path”

#Now, move/rename the files with given condition
#use ‘find’ command to find file path with given old extensions
for file_name in $(find $path -type f -name “*.${old_extension}”)
do
echo “renaminng $file_name to ${file_name%.${old_extension}}.${new_extension}”
mv -f $file_name ${file_name%.${old_extension}}.${new_extension}
done

#done
root@arunbagul:/home/arun#

NOTE :- Remember that this script is using ‘find’ command to find the files with given extensions
before renaming the files.. As ‘find’ command has no options to limit searching of files non recursively..
But still we can achieve non recursive renaming of files with same pattern matching and
string operation funcationality of shell script… please visit again!!

Thank you,

Arun Bagul

(0) Comments    Read More   
Mar
08
Posted on 08-03-2008
Filed Under (General information) by Arun Bagul

virtualbox

Introduction – VirtualBox is open source virtualization solution by Innotek GmbH (which is recently acquire by Sun Microsystem) for x86 hardware. Virtualization is a technique for hiding the physical characteristics of computing resources from the way in which other systems, applications, or end users interact with those resources. There are two types of virtualization…

  • Platform virtualization – is the combination of hardware and software. On a given hardware platform by host software (a control program), which creates a simulated computer environment, a virtual machine, for its guest software. The guest software, which is often itself a complete operating system, runs just as if it were installed on a stand-alone hardware platform.
  • Resource virtualization– is the process of virtualization of specific system resources, such as storage volumes, name spaces, and network resources. for e.g. Grid compiting, RAID devices, storage network, SAN , VPN etc.

VirtualBox is full virtualization which allows unmodified operating system with all of its installed software to run in a special environment, on top of your existing operating system. This environment, called a virtual machine, is created by the virtualization software by intercepting access to certain hardware components and certain features. The physical computer is then usually called the host, while the virtual machine is often called a guest. Guest operating system on virtual host runs same on the virtual box as it’s running on real machine.

VirtualBox is also different from so-called ‘paravirtualization’ solutions such as Xen, which require that the guest operating system be modified. In paravirtualization the virtual machine provides special API that can only be used by modifying Guest Operating System.

Presently, VirtualBox runs on Windows, Linux, Macintosh and OpenSolaris hosts and supports a large number of guest operating systems including but not limited to Windows (NT 4.0, 2000, XP, Server 2003, Vista), DOS/Windows 3.x, Linux (2.4 and 2.6), and OpenBSD. You can download VirtualBox from URL http://virtualbox.org/wiki/Downloads…

Thank you,

Arun

(1) Comment    Read More   
Mar
04

Introduction – some one ask me about man pages specially development related man pages, which was not installed on Ubuntu by default. System call and function related man pages are very useful to the programmers. So this article will help you to do this in two steps….

1] Search man pages –

root@arunbagul:~# apt-cache search dev man pages

* This command will display most of the packages related to man pages…

2] Install development man pages –

root@arunbagul:~# apt-get install manpages-dev
Reading package lists… Done
Building dependency tree
Reading state information… Done
…..
……
Get:1 http://in.archive.ubuntu.com gutsy/main manpages-dev 2.62-1 [1252kB]
Fetched 1252kB in 9s (137kB/s)
Selecting previously deselected package manpages-dev.
(Reading database … 113515 files and directories currently installed.)
Unpacking manpages-dev (from …/manpages-dev_2.62-1_all.deb) …
Setting up manpages-dev (2.62-1) …
root@arunbagul:~#

3] How to read man pages…

root@arunbagul:~# man 3 <func_name>
root@arunbagul:~# man 3 putc
root@arunbagul:~# man 3 system
root@arunbagul:~# man 3 exec
root@arunbagul:~#

4] Short notes on manual pages –

Types of Manual pages –

1   Executable programs or shell commands
2   System calls (functions provided by the kernel)
3   Library calls (functions within program libraries)
4   Special files (usually found in /dev)
5   File formats and conventions eg /etc/passwd
6   Games
7   Miscellaneous  (including  macro  packages and conven‐
tions), e.g. man(7), groff(7)
8   System administration commands (usually only for root)
9   Kernel routines [Non standard]
Thank  you,
Arun

(0) Comments    Read More   
Mar
03
Posted on 03-03-2008
Filed Under (General information) by Arun Bagul

Introduction-

andLinux is an Ubuntu system that runs seamlessly in Windows (2000, 2003, XP & Vista). It works only with 32 bit version of Windows. You can run andLinux without installing a virtual machine.
andLinux uses CoLinux as its core. CoLinux is a port of the Linux kernel to Windows. CoLinux differs itself from VMWare or Virtualbox by being more of a merger of Windows and the Linux kernel and not an emulated PC. Xming is used as X server and PulseAudio as sound server.

To start Linux applications, you may either use the XFCE Panel or you may choose to use the andLinux Launcher, which ships with andLinux. andLinux launcher consists of

  • Quicklaunch icons (e.g. for the file manager or the terminal)
  • Start menu in the system tray (next to the clock) which can be adapted to your own needs
  • Explorer shell extensions, i.e. context menu item, with which you can open a folder in the file manager / terminal or open a file with the text editor.
  • File type associations at your choice (e.g. for KOffice files, .tex / .dvi / .ps / .pdf files)
  • andCmd.exe to run linux commands from Windows scripts

Security warning: According to andLinux It is recommended to use andLinux only on single-user-PCs or in a trustworthy environment because the communication with the X-Server and the launcher is not secured, i.e., every user who can login to Windows can access andLinux.

Screenshot –

andlinux

(1) Comment    Read More   

www.flickr.com
arunbagul's photos More of arunbagul's photos
Get Adobe Flash player
-->