Tuesday, February 28, 2006

Convert your AVI files to MPEG Format in Linux

I had some movies that I wanted to Play in my DVD Player, So I had converted the same from .avi files to mpeg format in Mandrake 2006 .

Heres what I did,

Download ffmpeg

[root@mybox Nayagan.DVDRip]# urpmi ffmpeg

ftp://ftp.planetmirror.com/pub/plf/mandrake/free/2006.0/
./i586/ffmpeg-0.4.9-0.pre1.6.1.20060plf.i586.rpm
installing ffmpeg-0.4.9-0.pre1.6.1.20060plf.i586.rpm from
/var/cache/urpmi/rpms

Preparing... #############################################
1/1: ffmpeg #############################################


To Check File Type Before Conversion :

[root@mybox Movies]# file Nayagan_CD1.avi
Nayagan_CD1.avi: RIFF (little-endian) data, AVI, 576 x 320, 25.00 fps
, video: DivX 3 Low-Motion, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)

To Convert from .avi to .mpg

[root@mybox Movies]# ffmpeg -i Nayagan_CD1.avi -ab 56 -ar 22050 -b 500 -s 320x240 Nayagan_CD1.mpg

This takes a good one hour as file size was around 700 MB

To Check File Type after the conversion:

[root@mybox Movies]# file Nayagan_CD1.mpg
Nayagan_CD1.mpg: MPEG sequence, v1, system multiplex

I still have to check if this works with my DVD player... will update this later.

Monday, February 27, 2006

Synergy - Share your mouse and keyboard among Multiple Computers

Synergy is a program that will let you use one keyboard and mouse on multiple computers and Operating Systems across a network.

The Best example I have seen in my office is being used in the NMC(Network Monitoring Centre).

Guys in NMC have to monitor flaps in network there are around 20 monitors Horizontally located which has MRTG graphs and other applications running this program lets them access all this from a single point.


If you are Mandrake 2006 user like me, then use urpmi (Software Manager)
to download Synergy.


[root@mybox Cafe M]# urpmi synergy

ftp://gd.tuwien.ac.at/pub/linux/Mandriva/official/2006.0/i586/media/
contrib/synergy-1.2.2-1mdk.i586.rpm
installing synergy-1.2.2-1mdk.i586.rpm from /var/cache/urpmi/rpms
Preparing... #############################################
1/1: synergy #############################################



A good Explanation of setting up synergy can be found here , here and ofcourse
their official site

Friday, February 24, 2006

Disaster Recovery Plans - Backup on Linux

What to Backup ?

Directories to backup is dictated by the partitions used in your Server.

Usually it is user data - /root, /etc, /home, /usr/local

Optionally backup log files and pending emails

/var/log, /var/spool/mail

What is the Backup Media ?

Backups should be on a different server or a Storage Device than the server/data you are trying to backup.

NEVER backup your data to the same partition, nor same disk

Different Scenarios of Backup :

Copying From one Harddisk to another on Same Server :

Type - 1

dd if=/dev/hda1 of=/dev/hdb1 bs=1024k

Incase the hda1 Fails, you can remove hda1 and boot with hdb1 as primary.

Type - 2

Copying /home on /dev/hda1 to a /dev/hdb1 ( backup disk )

#mount /dev/hdb1 /mnt/backup

#( tar cf - /home ) | ( cd /mnt/backup ; tar xvfp - )

#umount /mnt/backup

Type - 3

scp Copying /home on /dev/hda1 to a /dev/hdb1 ( backup disk )

#mount /dev/hdb1 /mnt/backup
# scp -par /home /mnt/backup
#
umount /mnt/backup

Type - 4 ( Consumes Good amount of memory )

find | cpio Copying /home on /dev/hda1 to a /dev/hdb1 ( backup disk )

#mount /dev/hdb1 /mnt/backup
#find /home -print | cpio -pm /mnt/backup
#umount /mnt/backup

To View Contents :
cpio -it < file.cpio

To Extract a file :
cpio -id "usr/share/file/doc/*" < file.cpio

Note : In the above examples /mnt/backup is in hda1

Examples of Incremental Backup script if planning to scp to a different server :

For Creating Date Stamps ---- date '+%Y%m%d'.tar.gz

Simplified tar --newer Incremental Backup example
  • LastBackupTime = `cat /Backup_Dir/Last.txt`
  • tar zcvf --newer $LastBackupTime /Backup_Dir/Date.x.tgz $DIRS
  • echo "Date" > /Backup_Dir/Last.txt
Simplified find | tar Incremental Backup example
  • Cnt = `cat /Backup_Dir/Last.txt`
  • find $DIRS -mtime -$Cnt -print | tar zcvf /Backup_Dir/Date.$Cnt.tgz -T -
  • echo "$Cnt +1" > /Backup_Dir/Last.txt
################################################

Wednesday, February 22, 2006

Preventing SSH Dictionary Attacks


One good way of Preventing SSH Attacks :


I have the following lines in my iptables config:

#iptables -N SSH_CHECK
#iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j SSH_CHECK
#iptables -A SSH_CHECK -m state --state NEW -m recent --set --name SSH
#iptables -A SSH_CHECK -m state --state NEW -m recent --update --seconds 60 --hitcount 4 --name SSH
#iptables -A SSH_CHECK -m state --state NEW -m recent --rcheck --seconds 60 --hitcount 4 --name SSH -j DROP

which basically Kick-Bans the source IP for 60 seconds if more than 3 connections are attempted in a 60 second limit.

I've found this to be 100% effective.

Vi Editor --- Adding a Word at the Beginning and Ending of all lines in a File

To add a word at the end of all lines in a file :

:%s/$/LastWord /g


To add a word at the beginning of all lines in a file:

:%s/^/FirstWord /g




Monday, February 20, 2006

Auto Login - Expect/Autoexpect

I have a Sify Broadband connection at home for which I have to Login everytime
I want to connect to internet.

The Process for connecting was like,

Below I am running the command manually:

#sifyconnect -l

Welcome to Sify BroadBand Service

username :sriramsreedhar
password :

Account Balance : 233.24
Product Code : AXAU
Expiry Date : 2006-03-19 19:30:23
Last Login : 2006-02-20 17:42:13

Mon Feb 20 20:01:38 2006

[root@mybox Download]#

All I wanted to do was run a script like say connectsify.sh which should autologin.

Heres what I did,

I have download expect-8.4.11-1mdk.i586.rpm from rpmfind.net

[root@mybox Download]# rpm -ivh expect-8.4.11-1mdk.i586.rpm
Preparing... ########################################### [100%]
1:expect ########################################### [100%]

The below command autoexpect will create a file called connect_to_sify.exp

[root@mybox Download]# autoexpect -f connect_to_sify.exp /usr/bin/sifyconnect -l
autoexpect started, file is connect_to_sify.exp
Welcome to Sify BroadBand Service

username :sriramsreedhar
password :

Account Balance : 233.24
Product Code : AXAU
Expiry Date : 2006-03-19 19:30:23
Last Login : 2006-02-20 17:42:13

Mon Feb 20 20:01:38 2006

[root@mybox Download]#

This is what connect_to_sify.exp generated :

[root@mybox Download]# cat connect_to_sify.exp
#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Mon Feb 20 20:00:57 2006
# Expect and autoexpect were both written by Don Libes, NIST.
#
# Note that autoexpect does not guarantee a working script. It
# necessarily has to guess about certain things. Two reasons a script
# might fail are:
#
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts. If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character. This
# pacifies every program I know of. The -c flag makes the script do
# this in the first place. The -C flag allows you to define a
# character to toggle this mode off and on.

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}

#
# 2) differing output - Some programs produce different output each time
# they run. The "date" command is an obvious example. Another is
# ftp, if it produces throughput statistics at the end of a file
# transfer. If this causes a problem, delete these patterns or replace
# them with wildcards. An alternative is to use the -p flag (for
# "prompt") which makes Expect only look for the last line of output
# (i.e., the prompt). The -P flag allows you to define a character to
# toggle this mode off and on.
#
# Read the man page for more info.
#
# -Don


set timeout -1
spawn /usr/bin/sifyconnect -l
match_max 100000
expect -exact "[32mWelcome to [0m[32mSify [0m[32mBroadBand Service[0m\r
\r
username :"
send -- "sriramsreedhar\r"
expect -exact "sriramsreedhar\r
password :"
send -- "password\r"
expect eof

[root@mybox Download]#

[root@mybox Download]# mv connect_to_sify.exp /usr/bin/connectsify.sh

Now I run the below command to connect,

[root@mybox Download]# connectsify.sh
spawn /usr/bin/sifyconnect -l
Welcome to Sify BroadBand Service

username :sriram564
password :

Login Success
Welcome sriram564,


Account Balance : 233.24
Product Code : AXAU
Expiry Date : 2006-03-19 19:30:23
Last Login : 2006-02-20 20:36:35

Mon Feb 20 20:43:58 2006


I will no more require to give my username and password for connecting to sify.

Friday, February 17, 2006

Sending Mail from command line "mail"

Check this post which has a good explanation on using mail command.

Sending Mails through Command line "mail"

If you have been using Linux for sometime now then you must have used the mail command to send mails.

There is a Mail Client "Mutt" that enables you to send mails from shell but I would still prefer a one liner .... command which is much quicker to send mails,
say for eg. say you want to schedule mails for cron jobs.

Thats why I prefer the good old "mail" command

I have a Postfix running as a mail server on my system which accepts mail from
sriram.com domain.

Now my requirement is to be able to use "mail" command with postfix.

Step 1

I downloaded a command line smtp client msmtp


root@mybox sriram]# urpmi msmtp
ftp://gd.tuwien.ac.at/pub/linux/Mandriva/official/2006.0/i586/media/
contrib/msmtp-1.4.4-1mdk.i586.rpm
installing msmtp-1.4.4-1mdk.i586.rpm from /var/cache/urpmi/rpms
Preparing... #############################################
1/1: msmtp #############################################

[root@mybox sriram]#


By default "mail" command can be found in most of the linux system.


Step 2

I created a .msmtprc file inside the home directory /home/sriram

This is created to tell msmtp which SMTP server you want to use, and the information needed to access that account.

[root@mybox sriram]# cat .msmtprc
account default
auto_from off
host 10.10.93.220
from sriram@sriram.com
user sriram@gmail.com

#account default
#auto_from off
#host smtp.gmail.com
#from sriram@gmail.com
#auth on
#password mypassword
#user sriram@gmail.com
#tls on
[root@mybox sriram]#


The above hashed lines are comment, you can follow the syntax given in the hash lines if you are using a mail server which has smtp authentication
configured or if you wish to use a external mail server.

Step 3

Now to tell "mail" command to use "msmtp"

I created a file .mailrc in /home/directory and added a line

set sendmail=/usr/bin/msmtp

Note: Make sure your msmtp is in /usr/bin.

[root@mybox sriram]# which msmtp
/usr/bin/msmtp
[root@mybox sriram]#

Thats it now the "mail" command should work !!!

Now using mail commands,

$ mail sriram@linux.com

Subject: Test email

I'm sending you this email.

^D

(The ^D is Control-D, used to denote an end of file.)

Now the nice thing about the old "mail" command is that it would
accept anything from standard input. So if I wanted to send sriram a
really long email I could put it in a big file, and pipe it into the

mail command:
$ cat bigfile.txt | mail -s "Dear Sriram" sriram@gmail.com

or

$ mail -s "Dear Sriram" sriram@gmail.com <. bigfile.txt


Sunday, February 12, 2006

Linux - Setting up System Alerts

Consider a scenario where you are the System Administrator of a company running vital services and you do not have access to your Servers on weekdays.

You may want the following things to happen :

---Send a Alert to you by way of mail in case the Service Fails.
Obviously, I dont check mails on weekdays, so I am redirecting it to my cell.

10-digit-no@Service-Provider.com

---Auto restart the Service upon checking if the service has stopped.

For this I have downloaded monit-4.7.tar.gz from :

You can download the above version from here

I Untarred it in,

#cd /home/sriram/Download

[root@mybox Download]# pwd
/home/sriram/Download

[root@mybox Download]# ls
flash-0.4.10/ monit-4.7/ monit-howto
flash-0.4.10.tgz monit-4.7.tar.gz phplist-2.10.2.tgz

Now to install it,
[root@mybox Download]#cd monit-4.7

[root@mybox monit-4.7]#./configure
[root@mybox monit-4.7]# make
[root@mybox monit-4.7]#make install

This has installed monit

Now Configuration,

You need to create a configuration file called .monitrc in your home directory

I created under /home/sriram

#touch .monitrc
#chmod 0700 .monitrc

Contents of my .monitrc file is as follows :

[root@mybox sriram]# cat .monitrc

#Monit Configuration file
#

set daemon 300
set logfile /var/log/monit

#set mailserver mail.sriram.com

check apache with pidfile /var/run/httpd.pid
group apache
start = "/etc/rc.d/init.d/httpd start"
stop = "/etc/rc.d/init.d/httpd stop"
if failed host 10.10.93.220 port 80 type tcp then restart
set alert sriram003@gmail.com with mail-format { from: sriram@sriram.com }

[root@mybox sriram]#

Explanation :

Line 1 sets daemon to check for services every 5 Minutes

Line 3 I have hashed, you can define which mailserver to use to
send alerts in case you are using other than localhost.

Rest of the things are pretty explanatory if you look at them
Note : Set is a Global Variable it applies to the whole of Monit Configuration.


Optional,

[root@mybox sriram]# cat .monitrc

#$Id: monit.html,v 1.1 2002/04/30 16:52:36 kclark Exp $
#

set daemon 300
set logfile /var/log/monit

check apache with pidfile /var/run/httpd.pid
group apache
start = "/etc/rc.d/init.d/httpd start"
stop = "/etc/rc.d/init.d/httpd stop"
if failed host 10.10.93.220 port 80 type tcp then restart
set alert sriram003@gmail.com with
mail-format {
from: sriram@sriram.com
subject: $SERVICE $EVENT at $DATE
message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
Yours sincerely,
Sriram
}



The file monitors http service and sends messages to my gmail account in case
a service fails and restarts the same.

Note Before Setting up Alerts you will need a running Smtp Server which can send mails from the domain specified in the From ID.

I have configured postfix to accept mails from sriram.com domain.

To start the monit Service I do,

[root@mybox sriram]# monit -c /home/sriram/.monitrc

Web-Based Monit :

Monit can also be access web based for checking services

Just add these 3 lines at the end of .monitrc file

set httpd port 2812 address localhost

allow localhost
allow admin:sriram

Line 1 specifies Monit should start its own Built in server and bind
the server to localhost only.

If you want the Monit Http server to be accessible from other systems
in your network simply omit the address to bind to.

Line 2 specifies access control to httpd server host allowed to connect to
httpd server should be listed with one or more allow host statement.

Line 3 specifies a Username:Password user for Basic Authentication

Although its not recommened to Web based Configuration if you are running
a Live Server which is accessible from outside.


For more information on monit to suit your needs visit:
http://www.tildeslash.com/monit/

Tuesday, February 07, 2006

Podcatching - Gnu Linux

One of my favourite pass time these days is to listen to podcasts.

I have come across a Podcatching Software that I will share with you.

"Podcatching" - This is good way of downloading podcast that you
often listen to, I tried BashPodder GUI ... It hardly took a
minutes time to configure it and start running.

bpgui.tar.gz is a 12 kb file that you download from here

Once you have downloaded , to get started you need Xdialog installed.

If you dont have one you can get it from here

If you are using Mandrake like me then you can fetch it from urpmi

#urpmi Xdialog

Once Installed ,

untar the bpgui.tar.gz in your preferrd directory.

I have untarred it in /ram/Softwares/Linux_Podcatching/bpgui

Make sure you change the permissions to execute and user who runs that.

[root@mybox bpgui]# ls
bp.conf bpgui.sh* BPGUI.xpm* podcast.log temp.log

Note :
bp.conf contains podcast feed list (from where u are fetching).

To start
#./bpgui.sh


This will list the BashPodder GUI Menu

Which has the following options

Scan for New Podcasts(that you have added)
Play Podcasts
Add a Podcasts
Modify Podcasts
Remove a Podcasts


Now all your downloaded popdcast will be located in your home Directory

/HomeDir/Podcasts------- Folder

If you are looking for some Linux oriented podcasts then click here

Thats it !!! Enjoy Listening to your Favourite podcasts.

Monday, February 06, 2006

BitTorrent - Download and play files of all types

If you are using Kazaa or any other p2p network like that, please do a clean install of your PC right now.

Here I will discuss on using Torrent for Sharing Files among your peers.

What is BitTorrent ?

BitTorrent
is the name of a client application for the torrent peer-to-peer (P2P) file distribution protocol created by programmer Bram Cohen using Python Language.

Unlike protocols such as FTP, BitTorrent groups multiple files into a single package called a torrent.

Like other P2P systems, BitTorrent does not use a dedicated server. Instead, the functions of a server are performed by the tracker, peers, and seeds.

The tracker allows clients to communicate with each other. A client -- called a peer when it has downloaded part of the torrent and a seed once it has downloaded the entire torrent -- acts as an additional source for the torrent.

There are many other clients available but BitTorrent is the fastest
and easiest to get you running.

For your Information even "NASA uses BitTorrent".

You can download the Linux vesrion from here

You can install the rpm package (BitTorrent-4.0.1-1.noarch.rpm)

noarch - No Architecture

How do I get started ?

The official BitTorrent distribution includes three client applications. You can use any of these applications to download BitTorrent files:

  • btdownloadheadless.py -- A text-based client that writes the status to standard output. Good for unattended downloads where the output is redirected to a file.
  • btdownloadcurses.py -- A text-based client that provides a pseudographical interface. Good for attended downloads to machines not running a GUI.
  • btdownloadgui.py -- A graphical client.
First thing you do after installing the BitTorrent client software
is search for a .torrent file that you need, say you are searching
for bryan adams songs.

Note : There are many torrent sites available you need to search the net

I go to bittorrents.com and search for Bryan Adams

This will list many sites that has Bryan Adams songs...

I click on link to download the .torrent file.

Usually .torrent files are not more than 25kb in size.

The torrent file contains metadata about all the files it
makes downloadable, including their names and sizes
and checksums of all pieces.

Now say I have downloaded the .torrent file which contains
the information about the things that I need to download
in /home/sriram/Torrent.

Now to dowload the songs I do,

#btdownloadheadless.py --responsefile /home/sriram/Torrent/filename.torrent

Thats it, the songs will now be downloaded.

Once you have downloaded a torrent, it is good manners to allow BitTorrent to continue to run so other clients can upload at least as much information as you have downloaded.

$ btdownloadheadless.py --max_upload_rate 8 --url http://torrent.dulug.duke.edu/heidelberg-binary-i386.torrent

This command uses a URL to specify a .torrent file and saves the downloaded files in a directory named heidelberg (the name of the Fedora release) as specified by the .torrent file.

The --max_upload_rate 8 option prevents BitTorrent from using more than 8 kilobytes per second of upstream bandwidth. BitTorrent usually gives higher download rates to clients that upload more, so feel free to increase this value if you have spare bandwidth. You need to leave enough free upstream bandwidth for the acknowledgment packets from your download to get through or your download will be very slow.

By default the client uploads to a maximum of seven other clients at once. You can change this value by specifying the --max_uploads argument, followed by the maximum number of concurrent uploads you wish to permit. The default value of 7 is usually appropriate for typical broadband connections.

After you give the preceding command, the screen quickly fills with output that looks similar to the following:

saving:        heidelberg-binary-i386
percent done: 0.0
time left: finishing in 27:09:04
download to: /home/max/heidelberg-binary-i386
download rate: 32.9 KB/s
upload rate: 0.0 KB/s
share rating: 0.000 (0.0 MB up / 1.2 MB down)
seed status: 30 seen now, plus 1 distributed copies (2:81.5%, 3:23.0%, 4:2.1%)
peer status: 5 seen now

The file size is that of all the files you are downloading: four ISO images and several smaller files. To abort the download, press Ctrl-C. The download will automatically resume from where it left off when you download the same torrent to the same location again.

Use the following command to perform the same download as in the previous example, this time throttling the rate and number of uploads to values sensible for modem users.

$ btdownloadcurses.py --max_upload_rate 3 --max_uploads 2 --url http://torrent.dulug.duke.edu/heidelberg-binary-i386.torrent

The preceding command displays output similar to the following:

file:     heidelberg-binary-i386
size: 2,467,681,047 (2 GiB)
dest: /home/max/heidelberg-binary-i386
progress: _________________________________________
status: finishing in 6:40:42 (1.0%)
dl speed: 285.6 KB/s
ul speed: 2.6 KB/s
sharing: 0.009 (0.1 MB up / 15.1 MB down)
seeds: 29 seen now, plus 0 distributed copies (1:0.8%, 2:0.0%, 3:0.0%)
peers: 1 seen now

Firewall

BitTorrent uses common ports 6881 to 6889. These should be forwarded to your local IP. In fact, you don't need to open more ports than 6881, since BT listens on that one by default and then goes higher until it stops at 6889. However, if you're running multiple torrents at once, you need to open one port per torrent.

To understand the Terminolgy and Technicalities of
BitTorrent in detail click here

Also check http://www.torrentflux.com, a Torrent Manager.

Friday, February 03, 2006

Sendmail and SMTP Authenticated Relay


This document is to configure SMTP server on Fedora Core 4,
to use it from anywhere without the necessity of opening up
the relay for public use and hence subjecting yourself to the
possibility of being blacklisted or ending up in other databases such as ORBS.

DRAC and SMTP AUTH are two different approach which addresses this.

The Purpose of this document is to explain the process of installation and Configuration of sendmail with relay for roaming users, ie,relay based on authentication.

With SMTP-AUTH client may indicate an authentication mechanism to the server, perform an authentication protocol exchange, and optionally negotiate a security layer for subsequent protocol interactions. Thisextension is a profile of the Cyrus Simple Authentication and Security Layer [SASL].

Platform: Fedora Core 4, Sendmail 8.13.5

Installation of sendmail with SASL support

a) Download sendmail source package from:

ftp://ftp.sendmail.org/pub/sendmail/sendmail.8.13.5.tar.gz

This is downloaded into /usr/local/src directory.

b) tar -zxvf sendmail.8.13.5
c) cd sendmail-8.13.5
d) cd devtools/Site
e) joe site.config.m4
f) Add the following lines to it:
APPENDDEF(`confENVDEF', `-DSASL')
APPENDDEF(`conf_sendmail_LIBS', `-lsasl')

g) cd /usr/local/src/sendmail-8.13.5/cf/cf
h) create a file called linux.mc with exactly the following lines:

OSTYPE(`linux')dnl
define(`confCONNECTION_RATE_THROTTLE',40)dnl
define(`confMAX_HOP',30)dnl
define(`confMAX_MESSAGE_SIZE',10000000)dnl
define(`confPRIVACY_FLAGS',`authwarnings,needmailhelo')dnl
define(`confQUEUE_LA',5)dnl
define(`confREFUSE_LA',10)dnl
define(`confTO_CONNECT', `1m')dnl
define(`confTO_IDENT',0s)dnl
define(`confTO_QUEUEWARN', `12h')dnl
define(`confTRY_NULL_MX_LIST',true)dnl
define(`STATUS_FILE',`/etc/mail/sendmail.st')dnl
define(`ALIAS_FILE',`/etc/mail/aliases')dnl
FEATURE(`local_procmail', `/usr/bin/procmail')dnl
FEATURE(`always_add_domain')dnl
define(`confCW_FILE',` /etc/mail/local-host-names')dnl
FEATURE(`smrsh')dnl
define(`confEBINDIR',`/usr/lib/libexec')dnl
FEATURE(`use_cw_file')dnl
FEATURE(`redirect')dnl
FEATURE(`virtusertable',` hash -o /etc/mail/virtusertable')dnl
FEATURE(`access_db')dnl
FEATURE(`blacklist_recipients')dnl
TRUST_AUTH_MECH(`GSSAPI DIGEST-MD5 PLAIN LOGIN PAM')dnl
define(`confAUTH_MECHANISMS', `GSSAPI DIGEST-MD5 PLAIN LOGIN PAM')dnl
MAILER(`smtp')dnl

i) run :
m4 ../m4/cf.m4 linux.mc > sendmail.cf
j) cp sendmail.cf /etc/mail
if /etc/mail does not exist , create it and then copy
k) cd /usr/local/src/sendmail-8.13.5/
l) groupadd -g smmsp; useradd -g smmsp smmsp
m) sh Build
n) sh Build install
o) create a file called /etc/rc.d/init.d/sendmail with following lines ( the standard redhat startup-script):

#!/bin/sh
#
#This shell script takes care of starting and stopping sendmail.
#
# chkconfig: 2345 80 30
# description: Sendmail is a Mail Transport Agent, which is the program # that moves mail from one machine to another.
# processname: sendmail
# config: /etc/sendmail.cf
# pidfile: /var/run/sendmail.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Source sendmail configureation.
if [ -f /etc/sysconfig/sendmail ] ; then
. /etc/sysconfig/sendmail
else
DAEMON=yes
QUEUE=1h
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/sbin/sendmail ] || exit 0
RETVAL=0
# See how we were called.
case "$1" in

start)
# Start daemons.

echo -n "Starting sendmail: "
/usr/bin/newaliases > /dev/null 2>&1

for i in virtusertable access domaintable mailertable ; do
if [ -f /etc/mail/$i ] ; then
makemap hash /etc/mail/$i < /etc/mail/$i fi done daemon /usr/sbin/sendmail $([ "$DAEMON" = yes ] && echo -bd) \

$([ -n "$QUEUE" ] &&amp; echo -q$QUEUE)

RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/sendmail
;;

stop)

# Stop daemons.
echo -n "Shutting down sendmail: "
killproc sendmail
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sendmail
;;

restart|reload)

$0 stop
$0 start
RETVAL=$?
;;

status)

status sendmail
RETVAL=$?
;;

*)

echo "Usage: sendmail {start|stop|restart|status}"
exit 1

esac

exit $RETVAL

********* End of start/stop sendmail script ************

0) use /etc/rc.d/init.d/sendmail start/stop to start/stop sendmail
p) cd /etc/mail
q) touch local-host-names access domaintable mailertable virtusertable
r) if not exist, create dir /var/spool/mqueue
Sendmail installation is complete

Authentication with PAM

Edit /usr/lib/sasl/Sendmail.conf. Add the following line to it:
pwcheck_method: PAM

Create /etc/pam.d/smtp with following lines:

#%PAM-1.0
auth required /lib/security/pam_pwdb.so shadow
account required /lib/security/pam_pwdb.so
session required /lib/security/pam_pwdb.so

Test your setup, by using clients like Outlook Express and relay mail through this server.

Taking Backups

I am Trying my hand on shell script.

What I wanted was I need to mention the name of file or directory
and it should take the back of that with Year, day, month, time etc...

Heres the script,

#!/bin/bash
echo Give the File or Directory Name for which Want you to take Backup :
read filename
if [ "$(tar czvf $filename.$(date +%Y%m%d-%H%M%S).tgz $filename)" ]; then
echo The Backup is taken
else
echo There is no Such File.
fi

and saved it as --- archive.sh

[root@mainproxy Unix_Shell]# ls
archive.sh doc

[root@mainproxy Unix_Shell]# ./archive.sh
Give the File or Directory Name for which Want you to take Backup :
doc
The Backup is taken

[root@mainproxy Unix_Shell]# ls
archive.sh doc doc.20060203-063542.tgz

Bash Programming can be found here and here.

Thursday, February 02, 2006

Installing and Configuring phpMyvisites

In my previous post I have mentioned about phpMyvisites.

Here I have Documented the Procedure I followed for
phpMyVisites Installation.

Steps For Configuring PhpMyVisites :

1) Untar the phpmyvisites_2_1.zip inside your Webserver Folder

2) Create the database with the required Permissions :

[root@mybox phpmv2]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8 to server version: 4.0.15

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database phpmyvisites;
Query OK, 1 row affected (0.08 sec)

mysql> GRANT ALL PRIVILEGES ON phpmyvisites.* TO phpmyvisites@localhost IDENTIFIED BY 'phpmyviites';
Query OK, 0 rows affected (0.29 sec)

3) Make sure you have GD Library Insatlled :
IF not, you cab download it from here

http://www.boutell.com/gd/


4) Follow the Installation from the Web Browser

I have Untarred it in PhpMyVisites inside my Web Folder

5) Set The permissions for the PhpMyVisites Directory to Writable.

6) Follow the 9 Steps given From Browser

http://localhost/phpMyVisites/phpmv2/

7) Now in the 5th Step of your Web Browser Installation You will
see General Setup - Please Take note of this Information

For Eg
Super Administrator login - sriram
Super Administrator password - sriram123

Note Passwords must contain Numbers

Receive an email each day per website containing statistics summary? Yes

8) In Step 7 you will need to add your site for which you want to Counter

Have to Fill the Following in Step 7

Site Name

Site main URL

Show the logo on your pages?
By allowing the display of the logo on your site, you will help publicize phpMyVisites and help it evolve more rapidly. It would also be a nice way to thank the authors who have spent many hours developing this Open Source, Free application.

Record GET variable? (URL variables) - Record ALL URL variables

9) Step 8 shows the Javascript code that you need to embed in to your site

Display Javascript code

To count all visitors, you must insert the javascript code on all of your pages.
Your pages do not have to be made with PHP, phpMyVisites will work on all kinds of pages (whether it is HTML, ASP, Perl or any other languages).

Here is the code you have to insert: (copy and paste on all your pages)

The Detailed Code will be Given you need Copy and paste the Javascript in the Index page.

Tips for advanced users (these tips will be integrated in a future documentation)
Classify pages into groups

This is VERY useful for huge WebSites with content separated into categories. As you can see on phpMyVisites online demonstration, you can classify your pages into groups. You browse the groups and pages very easily in the phpMyVisites interface in the "Pages view" part. To do this, it is very simple (thanks to phpMyVisites supreme power)

You have 3 working modes :

- automatic : if your website is physically structured with directories, phpmyvisites will detect them and class your pages into groups (named as your site directories)

- manual : if you don't have directories, for example if all your pages call "index.php" with different variables, you can set up a virtual page name and assign its value to the Javascript variable "pagename", separating the groups with the character slash "/"
pagename = 'group1/subgroup1/infinitegroup/hello_kitty';


You can also set up a semi-automatic pagename using the HTML value of the TITLE markup (but there won't be group hierarchy)
pagename = document.title;

Count files download and/or URL clicks

If you want to count file downloads, or URL clicks, it is very simple. You have to change your URLs with the pattern :
http://PATH_TO_YOUR_PHPMYVISITES/phpmyvisites.php?url=URL_WHERE_TO_REDIRECT&id=ID_SITE&pagename=FILE:NAME_OF_FILE

Note that the string "FILE:" is mandatory! If you don't put this string, it won't work

For example, if you want to set up a Google url click count, instead of linking to "http://www.google.com", you will link to
phpmyvisites.php?url=http://www.google.com&id=1&pagename=FILE:google click count
Or if you want to count the files download (this link will redirect to "http://www.download.com/phpmyvisites.zip")
phpmyvisites.php?url=http://www.download.com/phpmyvisites.zip&id=1&pagename=FILE:phpmyvisites_last_version
A super tip

You can classify Files download, URL count, into groups! As you can for the classic pages. It allows to have a very precise report, well organized

For example this will word
phpmyvisites.php?url=http://download.com/phpmv.zip&id=1&pagename=FILE:files download/phpmyvisites/last release

The "File" will be classified into the groups files download/phpmyvisites/
Good luck with phpmyvisites!

If you're happy with it, don't hesitate to make a little donation, it helps us a lot :-) See on the official website for more information

Go to next step > Takes you to Finished Page.


That's all !!!

Analysing Web traffic with phpMyVisites

Any Web site owner knows the value of traffic statistics, but finding the right Web statistics package is not as easy as it may seem. Of course, there are excellent packages such as AWStats, Modlogan, and Webalizer, but these applications are overkill for people running smaller Web sites. Moreover, you can't install them if your Web hosting provider doesn't allow you to use custom scripts. If you are in the market for an easy-to-use program that provides essential Web traffic information, you might want to take a closer look at phpMyVisites.

The phpMyVisites installation script does all the dirty work for you, unlike many PHP/MySQL-based applications, which often require you to gather information and tweak configuration files manually. According to phpMyVisites, the installation procedure consists of nine steps and takes about 10 minutes. In reality, it's possible to perform the installation procedure even faster.

Download the latest version of phpMyVisites, unpack it, and copy the phpMyVisites folder (called phpmv2) to your Web server.

Point your browser at http://yourserver/phpmv2/ to begin the installation procedure. The phpMyVisites installation script starts by checking your server and database configuration, and presents the result as an easy-to-understand report.

Next, it prompts you to enter your MySQL database name and login info, which the script uses to connect to the database and populate it with the necessary tables. That's all there is to it. All you have to do now is to create an administrator account that will allow you to manage phpMyVisites as well as add and configure the Web site(s) you want phpMyVisites to monitor. Once you have done this, copy the provided JavaScript snippet and paste it into every page on your Web site.

phpMyVisites features

Now, let's take a look at what phpMyVisites has to offer. The Administration panel allows you to configure phpMyVisites' settings. Besides the usual stuff like server info, user management, and general settings, there are a couple of rather clever features. For example, you can configure phpMyVisites to send you or any other user daily email messages containing Web statistics, or you can view statistics using phpMyVisites' RSS feed. phpMyVisites also allows you to exclude a range of IP addresses and your own machine from being counted.

Let's say you maintain a newsletter and you want to know how many readers actually visit your Web site. With phpMyVisites you can do that by specifying the newsletter in the Administration section and using a special URL in the newsletter itself. If you cooperate with other sites, you might want to know how many visitors they sent to your Web site.

phpMyVisites can help you track visits from a partner's Web site -- just add the partner in the Administration panel.

This article was taken from here

Wednesday, February 01, 2006

Setting File Handles

Setting File Handles


The maximum number of file handles denotes the maximum number of open files that you can have on the Linux system.

Setting System Wide Limit for File Handles

The value in /proc/sys/fs/file-max sets the maximum number of file handles or open files that the Linux kernel will allocate. When you get error messages about running out of file handles, then you might want to raise this limit. The default value on RH 2.1AS is 8192.

For an Oracle server it is recommended that the file handles for the entire system is set to at least 65536.

To determine the maximum number of file handles for the entire system, run:

cat /proc/sys/fs/file-max

To determine the current usage of file handles, run:

$ cat /proc/sys/fs/file-nr
1154 133 8192

The file-nr file displays three parameters:
- Total allocated file handles
- Currently used file handles
- Maximum file handles that can be allocted (see also file-max)

The kernel dynamically allocates file handles whenever a file handle is requested by an application, but the kernel does not free these file handles when they are released by the application. The kernel recycles these file handles instead. This means that over time the total number of allocated file handles will increase even though the number of currently used file handles may be low.

The maximum number of file handles can be changed in the proc file system without reboot:

su - root
echo “65536″ > /proc/sys/fs/file-max

Alternatively, you can use sysctl(8) to change it:

sysctl -w fs.file-max=65536

To make the change permanent, add or change the following line in the file /etc/sysctl.conf. This file is used during the boot process.

echo “fs.file-max=65536″ >> /etc/sysctl.conf