Unix Blog !

February 28, 2006

Convert your AVI files to MPEG Format in Linux

Filed under: Uncategorized — sriram003 @ 3:50 pm

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 320×240 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.

February 27, 2006

Synergy – Share your mouse and keyboard among Multiple Computers

Filed under: Uncategorized — sriram003 @ 2:02 pm

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

February 24, 2006

Disaster Recovery Plans – Backup on Linux

Filed under: Uncategorized — sriram003 @ 3:29 pm

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

################################################

February 22, 2006

Preventing SSH Dictionary Attacks

Filed under: Uncategorized — sriram003 @ 3:55 pm

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

Filed under: Uncategorized — sriram003 @ 12:52 pm

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

February 20, 2006

Auto Login – Expect/Autoexpect

Filed under: Uncategorized — sriram003 @ 3:03 pm

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.

February 17, 2006

Sending Mail from command line "mail"

Filed under: Uncategorized — sriram003 @ 3:53 pm

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


February 12, 2006

Linux – Setting up System Alerts

Filed under: Uncategorized — sriram003 @ 5:14 pm

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/

February 7, 2006

Podcatching – Gnu Linux

Filed under: Uncategorized — sriram003 @ 2:59 pm

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.

February 6, 2006

BitTorrent – Download and play files of all types

Filed under: Uncategorized — sriram003 @ 5:37 am

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.

Older Posts »

Blog at WordPress.com.