<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5030911595679452622</id><updated>2011-11-27T15:18:20.142-08:00</updated><title type='text'>On My wall</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blogblowbando.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://blogblowbando.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Supratim Bandyopadhyaya</name><uri>http://www.blogger.com/profile/18354782392378655303</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5030911595679452622.post-7507481520261886981</id><published>2009-12-22T06:11:00.000-08:00</published><updated>2011-07-18T23:06:59.037-07:00</updated><title type='text'></title><content type='html'>&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5030911595679452622-7507481520261886981?l=blogblowbando.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blogblowbando.blogspot.com/feeds/7507481520261886981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5030911595679452622&amp;postID=7507481520261886981' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/7507481520261886981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/7507481520261886981'/><link rel='alternate' type='text/html' href='http://blogblowbando.blogspot.com/2009/12/my-understanding-on-my-youth-and.html' title=''/><author><name>Supratim Bandyopadhyaya</name><uri>http://www.blogger.com/profile/18354782392378655303</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5030911595679452622.post-8987160695747934065</id><published>2009-08-05T21:57:00.001-07:00</published><updated>2009-08-05T21:58:35.393-07:00</updated><title type='text'>Connecting IIS and Apache Tomcat</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Apache tomcat is one of the most popular application servers on java platform. But when it comes to serving static web content in parallel with web applications, there should be a clear separation of job role as http servers like apache and IIS are better at serving static content. &lt;br/&gt;&lt;br/&gt; This can be achieved by leaving static content to IIS and routing dynamic part to Tomcat. Thanks to apache , this is possible with JK connector which is an isapi filter, can be configured to work with IIS (checked with 5 and 6).&lt;br/&gt;&lt;br/&gt; So,let's get started!&lt;br/&gt;&lt;br/&gt;&lt;ul&gt;&lt;li&gt;We need the connector extension installed first!&lt;/li&gt;&lt;li&gt;&lt;a href='http://tomcatisapiinstaller.googlecode.com/files/IsapiRedirect-1.2.27.msi' target='_blank'&gt;Download and install the isapi extension (no hassel)&lt;/a&gt;&lt;/li&gt;&lt;li&gt;By default the filter installs in C:\Program Files\Apache Software Foundation\Jakarta Isapi Redirector. All the configuration files (workers.properties.minimal and uriworkermap.properties) are found in the directory named &lt;b&gt;conf&lt;/b&gt;.&lt;br/&gt;&lt;/li&gt;&lt;li&gt;make sure tomcat has an &lt;b&gt;ajp&lt;/b&gt; listener running on the same port as mentioned in &lt;font color='#000099'&gt;&lt;b&gt;workers.properties.minimal &lt;br/&gt;&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font color='#000099'&gt;&lt;font color='#000000'&gt;Look for the following lines in server.xml in &amp;lt;Tomcat base&amp;gt;/conf to make sure ajp is enabled &lt;br/&gt; &lt;b&gt;&amp;lt;!-- Define an AJP 1.3 Connector on port 8009 --&amp;gt;&lt;br/&gt;    &amp;lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /&amp;gt;&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;&lt;/font&gt;&lt;/font&gt;&lt;/li&gt;&lt;li&gt;add a couple of context forwarding (you can add &lt;b&gt;/manager/*=wlb&lt;/b&gt;&lt;br/&gt; just to check!)to tomcat in &lt;font color='#000099'&gt;&lt;b&gt;uriworkermap.properties&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;&lt;li&gt;run tomcat&lt;/li&gt;&lt;li&gt;Open the Internet Information Services(IIS) manager.&lt;br/&gt;&lt;/li&gt;&lt;li&gt;Browse to &amp;lt;server name&amp;gt; -&amp;gt; Web Sites&lt;br/&gt;&lt;/li&gt;&lt;li&gt;Right click on Default Web Site, then select New -&amp;gt; Virtual Directory.&lt;br/&gt;Enter Jakarta for Alias name and select jakarta isapi redirector install dir/bin as directory.&lt;br/&gt;&lt;/li&gt;&lt;li&gt;For the permission page, select both Read and Execute check boxes.&lt;br/&gt;Click Apply and close the dialog.&lt;br/&gt;&lt;/li&gt;&lt;li&gt;Right click on Default Web Site, and select properties.&lt;br/&gt;In the popup dialog, select the ISAPI Filters tab.&lt;br/&gt;Click Add.&lt;br/&gt;&lt;/li&gt;&lt;li&gt;Enter jakarta for Filter name, and jakarta isapi redirector install dir\bin\isapi_redirect.dll as executable.&lt;br/&gt;Click Apply and close the dialog box.&lt;br/&gt;&lt;/li&gt;&lt;li&gt;Right click on Web Service Extensions and select Add a new Web service extension. Enter tomcat connector for Extension Name, and add jakarta isapi redirector install dir\bin\isapi_redirect.dll for required files field.&lt;br/&gt;Select the Set extension status to Allowed check box and click OK to close the dialog box.&lt;br/&gt;&lt;/li&gt;&lt;li&gt;Stop and restart the Default Web Site by right clicking on it and select Stop and Start.&lt;br/&gt;&lt;/li&gt;&lt;li&gt;If that doesn't work try restarting iis admin service from IIS in MMC&lt;br/&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br/&gt; &lt;br/&gt;&lt;br/&gt;&lt;div class='zemanta-pixie'&gt;&lt;img src='http://img.zemanta.com/pixy.gif?x-id=27fb6dc3-12d2-8f99-8c6e-fb3990d96fc2' alt='' class='zemanta-pixie-img'/&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5030911595679452622-8987160695747934065?l=blogblowbando.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blogblowbando.blogspot.com/feeds/8987160695747934065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5030911595679452622&amp;postID=8987160695747934065' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/8987160695747934065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/8987160695747934065'/><link rel='alternate' type='text/html' href='http://blogblowbando.blogspot.com/2009/08/connecting-iis-and-apache-tomcat.html' title='Connecting IIS and Apache Tomcat'/><author><name>Supratim Bandyopadhyaya</name><uri>http://www.blogger.com/profile/18354782392378655303</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5030911595679452622.post-4732683156358905910</id><published>2009-06-24T07:59:00.001-07:00</published><updated>2009-06-24T07:59:24.471-07:00</updated><title type='text'>Making movies from image files using ffmpeg/mencoder Motivation</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;In my research, I often generate a sequence of images from either my&lt;br/&gt;experiment or from a simulation that I want to put together into a movie.&lt;br/&gt;Since I use linux, I wanted to do this using free software in linux, and I&lt;br/&gt;wanted to be able to play the movie in linux. This webpage outlines what I've&lt;br/&gt;learned about how to do this in linux using mencoder or ffmpeg to create high&lt;br/&gt;quality files that are well compressed and the play well under all operating&lt;br/&gt;systems.&lt;br/&gt;&lt;br/&gt;The movies are going to be non-standard size (usually square, around 200x200&lt;br/&gt;pixels for me), and have a non-standard frame rate: typcially, my movies may&lt;br/&gt;only be 10 frames, so I don't want to run it at 30 fps.&lt;br/&gt;The details&lt;br/&gt;&lt;br/&gt;We want to encode to some kind of relatively portable movie format. ffmpeg and&lt;br/&gt;mencoder both do this using the libavcodec library developed as part of&lt;br/&gt;ffmpeg. The codec options from the mencoder man page include:&lt;br/&gt;&lt;br/&gt;      vcodec=&lt;br/&gt;              Employ the specified codec (default: mpeg4).&lt;br/&gt;                 mjpeg&lt;br/&gt;                      Motion JPEG&lt;br/&gt;                 ljpeg&lt;br/&gt;                      Lossless JPEG&lt;br/&gt;                 h263&lt;br/&gt;                      H.263&lt;br/&gt;                 h263p&lt;br/&gt;                      H.263+&lt;br/&gt;                 mpeg4&lt;br/&gt;                      MPEG-4 (DivX 4/5)&lt;br/&gt;                 msmpeg4&lt;br/&gt;                      DivX 3&lt;br/&gt;                 msmpeg4v2&lt;br/&gt;                      MS MPEG4v2&lt;br/&gt;                 wmv1&lt;br/&gt;                      Windows Media Video, version 1 (AKA WMV7)&lt;br/&gt;                 wmv2&lt;br/&gt;                      Windows Media Video, version 2 (AKA WMV8)&lt;br/&gt;                 rv10&lt;br/&gt;                      an old RealVideo codec&lt;br/&gt;                 mpeg1video&lt;br/&gt;                      MPEG-1 video&lt;br/&gt;                 mpeg2video&lt;br/&gt;                      MPEG-2 video&lt;br/&gt;                 huffyuv&lt;br/&gt;                      HuffYUV&lt;br/&gt;                 asv1&lt;br/&gt;                      ASUS Video v1&lt;br/&gt;                 asv2&lt;br/&gt;                      ASUS Video v2&lt;br/&gt;                 ffv1&lt;br/&gt;                      FFmpeg's lossless video codec&lt;br/&gt;&lt;br/&gt;ffmpeg supports an even larger list of output codecs and container formats.&lt;br/&gt;&lt;br/&gt;MPEG-1 and MPEG-2 streams are no good, since the frame rate is locked to 29.97&lt;br/&gt;or 25 FPS. For an excellent overview of some of the common open-standard&lt;br/&gt;compression methods, see this page.&lt;br/&gt;&lt;br/&gt;(Note: "open" standard only means that the specifications aren't some&lt;br/&gt;undocumented industry secret. It does not mean, however, that the formats are&lt;br/&gt;not entrenched with patent issues, which mpeg4, and even mpeg1 and mpeg2,&lt;br/&gt;most certainly are...You take what you can get, though.)&lt;br/&gt;&lt;br/&gt;MJPEG would seem to be a good option, except that the files that we get seem&lt;br/&gt;to be incompatible with windows media player for some reason (at least with&lt;br/&gt;files encoded with mencoder). MJPEG supports arbitrary frame rates, but the&lt;br/&gt;movies files could get large if you have a lot of frames since it doesn't use&lt;br/&gt;temporal coding.&lt;br/&gt;&lt;br/&gt;MPEG-4 is the best option. The mpeg4 stream can be stored in either in&lt;br/&gt;the .avi or .mp4 (quicktime) container file: it can support high levels of&lt;br/&gt;lossy compression to keep file sizes small and also supports arbitrary frame&lt;br/&gt;rates. It is also translates much more easily to other platforms than wmv1 or&lt;br/&gt;wmv2.&lt;br/&gt;&lt;br/&gt;mencoder only supports avi file containers, which is a pity since the&lt;br/&gt;quicktime widgets looks nicer, and the .mp4 container format has fewer issues&lt;br/&gt;with compatibility (there are some fourcc issues with .avi: this container&lt;br/&gt;file format issue is the only reason why the mpeg4 streams inside avi files&lt;br/&gt;from DiVX, xvid, ..., codecs are incompatible! How stupid is that?)&lt;br/&gt;&lt;br/&gt;Note also that mencoder (at least version 1.0pre6-3.3.3 does) will barf if we&lt;br/&gt;use anything other than jpeg files as our input, so we should convert all our&lt;br/&gt;images to jpeg's with 100% quality to avoid any quantization loss at this&lt;br/&gt;stage:&lt;br/&gt;&lt;br/&gt; $ for f in *ppm ; do convert -quality 100 $f `basename $f ppm`jpg; done&lt;br/&gt;&lt;br/&gt;With mencoder, we can use the vbitrate option to set the degree of lossy&lt;br/&gt;compression. Note that the default mpeg4 option will add a "DivX" logo to the&lt;br/&gt;movie when playin in windows media player, so we prefer to use one of the&lt;br/&gt;other mpeg4 encoders, such as msmpeg4 or msmpeg4v2. The commmand line I've&lt;br/&gt;used is:&lt;br/&gt;&lt;br/&gt;mencoder "mf://*.jpg" -mf fps=10 -o test.avi -ovc lavc -lavcopts&lt;br/&gt;vcodec=msmpeg4v2:vbitrate=800&lt;br/&gt;&lt;br/&gt;We can also use ffmpeg directly to encode the images files into a movie. If we&lt;br/&gt;start with files name 001.jpg, 002.jpg, ..., we can use:&lt;br/&gt;&lt;br/&gt;ffmpeg -r 10 -b 1800 -i %03d.jpg test1800.mp4&lt;br/&gt;&lt;br/&gt;This works very well, and is nice because ffmpeg is included in debian! My&lt;br/&gt;only complaint is that with ffmpeg is that you have to be careful that all&lt;br/&gt;the files are named sequentially. For example, for a long time, I was missing&lt;br/&gt;015.jpg, which caused it to encode only 15 frames. To get it to work, I had&lt;br/&gt;to rename the files so that there were no gaps in the file numbers. The .mp4&lt;br/&gt;files encoded this way will play fine with quicktime under windows, which I&lt;br/&gt;peronally prefer over media player, and which will never show the stupid DiVX&lt;br/&gt;logo, since it's doesn't use the braindead avi container. (see rant above...)&lt;br/&gt;&lt;br/&gt;How do the file sizes compare?&lt;br/&gt;&lt;br/&gt;Image files:&lt;br/&gt;&lt;br/&gt;Initial ppms: 6.9 MB&lt;br/&gt;Initial jpgs: 8.0 MB (100% quality)&lt;br/&gt;&lt;br/&gt;Movies (10 frames per second): avi files are encoded using mspeg4v2, mp4 files&lt;br/&gt;are done using the ffmpeg default (mpeg4).&lt;br/&gt;&lt;br/&gt;1500 test1800.avi&lt;br/&gt; 900 test800.avi&lt;br/&gt; 528 test400.avi&lt;br/&gt;&lt;br/&gt;1748 test1800.mp4&lt;br/&gt; 860 test800.mp4&lt;br/&gt; 504 test400.mp4&lt;br/&gt; 324 test200.mp4&lt;br/&gt; 264 test100.mp4&lt;br/&gt;&lt;br/&gt;At 1800 kbits/sec, the quality is excellent, with no noticeable motion&lt;br/&gt;artifacts. 800 is very good, but at 400, the motion artifacts become quite&lt;br/&gt;noticeable.&lt;br/&gt;&lt;br/&gt;Other useful stuff:&lt;br/&gt;&lt;br/&gt;    * Get a thumbnail from a movie using ffmpeg:&lt;br/&gt;&lt;br/&gt;      ffmpeg -i test.mp4 -f singlejpeg -t 0.001 test.jpg&lt;br/&gt;&lt;br/&gt;    * Movies can be embedded in pdf documents using latex! Use the style file&lt;br/&gt;movie15.sty. This is really cool!&lt;br/&gt;&lt;br/&gt;      Check out this file for an example (latex source file is available&lt;br/&gt;here). More info about how to do this is avilable from this website.&lt;br/&gt;&lt;br/&gt;      The movies will play fine under windows using acroread 7.0. Under linux,&lt;br/&gt;if you install acrobat reader 7.0 for linux, you can save the embedded movies&lt;br/&gt;to disk and play them form there.&lt;br/&gt;&lt;br/&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5030911595679452622-4732683156358905910?l=blogblowbando.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blogblowbando.blogspot.com/feeds/4732683156358905910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5030911595679452622&amp;postID=4732683156358905910' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/4732683156358905910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/4732683156358905910'/><link rel='alternate' type='text/html' href='http://blogblowbando.blogspot.com/2009/06/making-movies-from-image-files-using.html' title='Making movies from image files using ffmpeg/mencoder Motivation'/><author><name>Supratim Bandyopadhyaya</name><uri>http://www.blogger.com/profile/18354782392378655303</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5030911595679452622.post-7688789323963906445</id><published>2009-06-24T07:56:00.001-07:00</published><updated>2009-06-24T07:56:55.115-07:00</updated><title type='text'>Linux Force Unmount Script</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;create a file in /usr/bin after chmod +x from root&lt;br/&gt;then copy the following script and save !&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;#!/bin/bash&lt;br/&gt;&lt;br/&gt;# TODO: accept either dir or device on command line (like umount does) &lt;br/&gt;#           ie: /mnt/tmp or /dev/hda6&lt;br/&gt;# TODO: accept relative dirs&lt;br/&gt;#           ie: cd /mnt; fumount tmp&lt;br/&gt;&lt;br/&gt;declare -rx SCRIPT=${0##*/}&lt;br/&gt;declare -rx VERSION=001&lt;br/&gt;&lt;br/&gt;if [ `whoami` != "root" ]; then&lt;br/&gt;    echo "You must run this as root"&lt;br/&gt;    exit 1&lt;br/&gt;fi&lt;br/&gt;&lt;br/&gt;# display script usage, then exit&lt;br/&gt;function usage {&lt;br/&gt;    printf "usage: $SCRIPT [-i] [-v] dir\n" &amp;gt;&amp;amp;2&lt;br/&gt;    printf "  -i : interactive mode\n" &amp;gt;&amp;amp;2&lt;br/&gt;    printf "  -v : verbose\n" &amp;gt;&amp;amp;2&lt;br/&gt;&lt;br/&gt;    success=1    # don't print failure message&lt;br/&gt;    exit 1&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;# print verbose/debug information&lt;br/&gt;function debug {&lt;br/&gt;    if [ -n "$verbose" ]; then&lt;br/&gt;        printf "$1"&lt;br/&gt;    fi&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;# umount was a success&lt;br/&gt;function success {&lt;br/&gt;    success=1&lt;br/&gt;    debug "$mntpoint unmounted\n"&lt;br/&gt;    exit 0&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;function on_exit {&lt;br/&gt;    if [ -z "$success" ]; then&lt;br/&gt;        printf "unmount failed\n" &amp;gt;&amp;amp;2&lt;br/&gt;    fi&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;trap on_exit EXIT&lt;br/&gt;&lt;br/&gt;# parse the arguments&lt;br/&gt;while [ -n "$1" ]; do&lt;br/&gt;    case $1 in&lt;br/&gt;    -i)&lt;br/&gt;        interactive=1&lt;br/&gt;        ;;&lt;br/&gt;    -v)&lt;br/&gt;        verbose=1&lt;br/&gt;        ;;&lt;br/&gt;    -*)&lt;br/&gt;        usage&lt;br/&gt;        ;;&lt;br/&gt;    *)&lt;br/&gt;        if [ -z "$mntpoint" ]; then&lt;br/&gt;            mntpoint=$1&lt;br/&gt;        else&lt;br/&gt;            usage&lt;br/&gt;        fi&lt;br/&gt;        ;;&lt;br/&gt;    esac&lt;br/&gt;&lt;br/&gt;    shift&lt;br/&gt;done&lt;br/&gt;&lt;br/&gt;if [ -z "$mntpoint" ]; then&lt;br/&gt;    usage&lt;br/&gt;fi&lt;br/&gt;&lt;br/&gt;# strip trailing slash from mntpoint&lt;br/&gt;# surely there must be a better way to do this...&lt;br/&gt;while [ "`echo "$mntpoint" |grep '/$'`" ]; do&lt;br/&gt;    mntpoint=${mntpoint%/}&lt;br/&gt;done&lt;br/&gt;&lt;br/&gt;# attempt a regular umount&lt;br/&gt;tryumount=`umount $mntpoint 2&amp;gt;&amp;amp;1`&lt;br/&gt;ret=$?&lt;br/&gt;if [ "`echo $tryumount |grep 'not mounted'`" ]; then&lt;br/&gt;    printf "%s is not mounted\n" "$mntpoint" &amp;gt;&amp;amp;2&lt;br/&gt;    if [ -e "$mntpoint" ]; then&lt;br/&gt;        printf "You must provide the full path (ie: /mnt/tmp)\n" &amp;gt;&amp;amp;2&lt;br/&gt;    fi&lt;br/&gt;&lt;br/&gt;    exit 1&lt;br/&gt;fi&lt;br/&gt;&lt;br/&gt;if [ "`echo $tryumount |grep 'not found'`" ]; then&lt;br/&gt;    printf "%s not fount\n" "$mntpoint" &amp;gt;&amp;amp;2&lt;br/&gt;    exit 1&lt;br/&gt;fi&lt;br/&gt;&lt;br/&gt;# did the umount succeed?&lt;br/&gt;if [ $ret -eq 0 ]; then&lt;br/&gt;    success&lt;br/&gt;else&lt;br/&gt;    # if the filesystem is busy, kill all processes accessing it&lt;br/&gt;    if [ "`echo $tryumount |grep 'busy'`" ]; then&lt;br/&gt;        debug "busy... killing all processes accessing the filesystem\n"&lt;br/&gt;&lt;br/&gt;        if [ "$interactive" ]; then&lt;br/&gt;            fuser -ki $mntpoint&lt;br/&gt;        else&lt;br/&gt;            fuser -k $mntpoint &amp;amp;&amp;gt; /dev/null&lt;br/&gt;        fi&lt;br/&gt;    else&lt;br/&gt;        printf "%s failed... umount returned %d\n" "$SCRIPT" "$ret" &amp;gt;&amp;amp;2&lt;br/&gt;        exit 1&lt;br/&gt;    fi&lt;br/&gt;fi&lt;br/&gt;&lt;br/&gt;# try to umount again&lt;br/&gt;tryumount=`umount $mntpoint 2&amp;gt;&amp;amp;1`&lt;br/&gt;ret=$?&lt;br/&gt;if [ $ret -eq 0 ]; then&lt;br/&gt;    success&lt;br/&gt;else&lt;br/&gt;    if [ "`echo $tryumount | grep 'busy'`" ]; then&lt;br/&gt;&lt;br/&gt;        # get the name of the device that is mounted&lt;br/&gt;        exec 6&amp;lt;&amp;amp;0    # save stdin... better way to do this?&lt;br/&gt;        exec &amp;lt; /proc/mounts&lt;br/&gt;        while read line; do&lt;br/&gt;            mnt=`echo $line |awk '{print $2}'`&lt;br/&gt;            if [ "$mnt" = "$mntpoint" ]; then&lt;br/&gt;                device=`echo $line |awk '{print $1}'`&lt;br/&gt;                break&lt;br/&gt;            fi&lt;br/&gt;        done&lt;br/&gt;        exec 0&amp;lt;&amp;amp;6 6&amp;lt;&amp;amp;-    # restore stdin&lt;br/&gt;&lt;br/&gt;        # our first attempt didn't work, do lazy umount to make it easier&lt;br/&gt;        debug "still busy, doing lazy umount\n"&lt;br/&gt;&lt;br/&gt;        if [ "$interactive" ]; then&lt;br/&gt;            printf "Do a lazy unmount? (y/N)\n"&lt;br/&gt;            read yn&lt;br/&gt;            if [ "$yn" != "y" ]; then&lt;br/&gt;                exit 1&lt;br/&gt;            fi&lt;br/&gt;        fi&lt;br/&gt;&lt;br/&gt;        umount -l $mntpoint&lt;br/&gt;&lt;br/&gt;        # keep trying to kill processes accessing the device. don't exit until&lt;br/&gt;        # we succeed&lt;br/&gt;        while [ -n "$device" -a -e "$device" ]; do&lt;br/&gt;            debug "attempting to kill all processes accessing $device\n"&lt;br/&gt;&lt;br/&gt;            if [ "$interactive" ]; then&lt;br/&gt;                fuser -kmi $device&lt;br/&gt;            else&lt;br/&gt;                fuser -km $device &amp;amp;&amp;gt; /dev/null&lt;br/&gt;            fi&lt;br/&gt;&lt;br/&gt;            if [ -z "`fuser -m $device`" ]; then&lt;br/&gt;                success&lt;br/&gt;            fi&lt;br/&gt;        done&lt;br/&gt;&lt;br/&gt;        printf "Lazy unmount succeeded, but I was unable to find the\n"&lt;br/&gt;        printf "device the filesystem was mounted on. There may still be\n"&lt;br/&gt;        printf "processes accessing the device.\n"&lt;br/&gt;&lt;br/&gt;        exit 0&lt;br/&gt;    else&lt;br/&gt;        printf "%s failed... umount returned %d\n" "$SCRIPT" "$ret" &amp;gt;&amp;amp;2&lt;br/&gt;        exit 1&lt;br/&gt;    fi&lt;br/&gt;fi&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5030911595679452622-7688789323963906445?l=blogblowbando.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blogblowbando.blogspot.com/feeds/7688789323963906445/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5030911595679452622&amp;postID=7688789323963906445' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/7688789323963906445'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/7688789323963906445'/><link rel='alternate' type='text/html' href='http://blogblowbando.blogspot.com/2009/06/linux-force-unmount-script.html' title='Linux Force Unmount Script'/><author><name>Supratim Bandyopadhyaya</name><uri>http://www.blogger.com/profile/18354782392378655303</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5030911595679452622.post-5676963973282828010</id><published>2009-06-24T07:52:00.001-07:00</published><updated>2009-06-24T07:52:32.664-07:00</updated><title type='text'>How to Monitor Remote JVM</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;/*&lt;br/&gt; * JVMRuntimeClient.java&lt;br/&gt; *&lt;br/&gt; * Created on March 9, 2007, 2:44 PM&lt;br/&gt; *&lt;br/&gt; * Copyright (c) Sun Microsystems, 2007 - All rights reserved.&lt;br/&gt; */&lt;br/&gt;&lt;br/&gt;package jvmruntime;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;import java.io.File;&lt;br/&gt;import java.lang.management.ManagementFactory;&lt;br/&gt;&lt;br/&gt;import java.net.InetAddress;&lt;br/&gt;import java.util.logging.Logger;&lt;br/&gt;&lt;br/&gt;import javax.management.remote.JMXServiceURL;&lt;br/&gt;import com.sun.tools.attach.VirtualMachine;&lt;br/&gt;&lt;br/&gt;import com.sun.tools.attach.VirtualMachineDescriptor;&lt;br/&gt;&lt;br/&gt;import java.lang.management.RuntimeMXBean;&lt;br/&gt;import java.util.ArrayList;&lt;br/&gt;&lt;br/&gt;import java.util.List;&lt;br/&gt;import javax.management.MBeanServerConnection;&lt;br/&gt;&lt;br/&gt;import javax.management.remote.JMXConnector;&lt;br/&gt;import javax.management.remote.JMXConnectorFactory;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;/**&lt;br/&gt; * Class JVMRuntimeClient - Shows how to programmatically connect to&lt;br/&gt; * a running VM and interact with its RuntimeMXBean.&lt;br/&gt; *&lt;br/&gt; * @author Sun Microsystems, 2007 - All rights reserved.&lt;br/&gt;&lt;br/&gt; */&lt;br/&gt;public class JVMRuntimeClient {&lt;br/&gt;    &lt;br/&gt;    /**&lt;br/&gt;     * A logger for this class.&lt;br/&gt;     **/&lt;br/&gt;&lt;br/&gt;    private static final Logger LOG =&lt;br/&gt;            Logger.getLogger(JVMRuntimeClient.class.getName());&lt;br/&gt;    &lt;br/&gt;&lt;br/&gt;    /** Creates a new instance of Main */&lt;br/&gt;    public JVMRuntimeClient() {&lt;br/&gt;    }&lt;br/&gt;&lt;br/&gt;    /**&lt;br/&gt;     * A helper class to analyze the command line and create a JMXServiceURL.&lt;br/&gt;&lt;br/&gt;     * Allows to pass a JMXServiceURL, a host and port, or a VM PID.&lt;br/&gt;     **/&lt;br/&gt;    public static class ConnectionArgs {&lt;br/&gt;&lt;br/&gt;        private static final String CONNECTOR_ADDRESS =&lt;br/&gt;          "com.sun.management.jmxremote.localConnectorAddress";&lt;br/&gt;&lt;br/&gt;        &lt;br/&gt;        &lt;br/&gt;        public final JMXServiceURL jmxURL;&lt;br/&gt;        final public String SYNTAX = "JVMRuntimeClient -url &amp;lt;jmx-url&amp;gt; " +&lt;br/&gt;&lt;br/&gt;                "| -port &amp;lt;port-number&amp;gt; [-host &amp;lt;host-or-ip] " +&lt;br/&gt;                "| -pid &amp;lt;pid&amp;gt; | -help";&lt;br/&gt;        &lt;br/&gt;        public ConnectionArgs(String[] args) {&lt;br/&gt;&lt;br/&gt;            jmxURL = parseArgs(args);&lt;br/&gt;        }&lt;br/&gt;        &lt;br/&gt;        public final JMXServiceURL getJMXServiceURL() {&lt;br/&gt;            return jmxURL;&lt;br/&gt;&lt;br/&gt;        }&lt;br/&gt;        &lt;br/&gt;        private JMXServiceURL parseArgs(String[] args) {&lt;br/&gt;            &lt;br/&gt;            String host = null;&lt;br/&gt;&lt;br/&gt;            int port = 0;&lt;br/&gt;            String pid = null;&lt;br/&gt;            JMXServiceURL serviceURL = null;&lt;br/&gt;            &lt;br/&gt;            for (int i=0;i&amp;lt;args.length;i++) {&lt;br/&gt;&lt;br/&gt;                &lt;br/&gt;                if (args[i].startsWith("-url")) {&lt;br/&gt;                // The '-url' option will let you specify a JMXServiceURL&lt;br/&gt;&lt;br/&gt;                // on the command line. This is an URL that begins with&lt;br/&gt;                // service:jmx:&amp;lt;protocol&amp;gt;&lt;br/&gt;                //&lt;br/&gt;&lt;br/&gt;                    if (host != null)&lt;br/&gt;                        throwSyntaxError(&lt;br/&gt;                                "-url and -host are mutually exclusive");&lt;br/&gt;&lt;br/&gt;                    if (pid != null)&lt;br/&gt;                        throwSyntaxError(&lt;br/&gt;                                "-pid and -url are mutually exclusive");&lt;br/&gt;&lt;br/&gt;                    if (port &amp;gt; 0)&lt;br/&gt;                        throwSyntaxError(&lt;br/&gt;                                "-port and -url are mutually exclusive");&lt;br/&gt;&lt;br/&gt;                    if (++i &amp;gt;= args.length)&lt;br/&gt;                        throwSyntaxError(&lt;br/&gt;                                "missing JMXServiceURL after -url");&lt;br/&gt;&lt;br/&gt;                    &lt;br/&gt;                    try {&lt;br/&gt;                        serviceURL = new JMXServiceURL(args[i]);&lt;br/&gt;                    } catch (Exception x) {&lt;br/&gt;&lt;br/&gt;                        throwSyntaxError("bad JMXServiceURL after -url: " + x);&lt;br/&gt;                    }&lt;br/&gt;                    continue;&lt;br/&gt;                    &lt;br/&gt;&lt;br/&gt;                } else if (args[i].startsWith("-host")) {&lt;br/&gt;                // The '-host' and '-port' options will let you specify a host&lt;br/&gt;&lt;br/&gt;                // and port, and from that will construct the JMXServiceURL of&lt;br/&gt;                // the default RMI connector, that is:&lt;br/&gt;                // service:jmx:rmi:///jndi/rmi://&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/jmxrmi"&lt;br/&gt;&lt;br/&gt;                //&lt;br/&gt;                    if (serviceURL != null)&lt;br/&gt;                        throwSyntaxError("-url and -host are mutually exclusive");&lt;br/&gt;&lt;br/&gt;                    if (pid != null)&lt;br/&gt;                        throwSyntaxError("-pid and -host are mutually exclusive");&lt;br/&gt;&lt;br/&gt;                    if (++i &amp;gt;= args.length)&lt;br/&gt;                        throwSyntaxError("missing host after -host");&lt;br/&gt;                    try {&lt;br/&gt;&lt;br/&gt;                        InetAddress.getByName(args[i]);&lt;br/&gt;                        host = args[i];&lt;br/&gt;                    } catch (Exception x) {&lt;br/&gt;                        throwSyntaxError("bad host after -url: " + x);&lt;br/&gt;&lt;br/&gt;                    }&lt;br/&gt;                    &lt;br/&gt;                } else if (args[i].startsWith("-port")) {&lt;br/&gt;                // The '-host' and '-port' options will let you specify a host&lt;br/&gt;&lt;br/&gt;                // and port, and from that will construct the JMXServiceURL of&lt;br/&gt;                // the default RMI connector, that is:&lt;br/&gt;                // service:jmx:rmi:///jndi/rmi://&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/jmxrmi"&lt;br/&gt;&lt;br/&gt;                //&lt;br/&gt;                    if (serviceURL != null)&lt;br/&gt;                        throwSyntaxError("-url and -port are mutually exclusive");&lt;br/&gt;&lt;br/&gt;                    if (pid != null)&lt;br/&gt;                        throwSyntaxError("-pid and -port are mutually exclusive");&lt;br/&gt;&lt;br/&gt;                    if (++i &amp;gt;= args.length)&lt;br/&gt;                        throwSyntaxError("missing port number after -port");&lt;br/&gt;                    try {&lt;br/&gt;&lt;br/&gt;                        port = Integer.parseInt(args[i]);&lt;br/&gt;                        if (port &amp;lt;= 0)&lt;br/&gt;                            throwSyntaxError("bad port number after -port: " +&lt;br/&gt;&lt;br/&gt;                                    "must be positive");&lt;br/&gt;                    } catch (Exception x) {&lt;br/&gt;                        throwSyntaxError("bad port number after -port: " + x);&lt;br/&gt;&lt;br/&gt;                    }&lt;br/&gt;                } else if (args[i].startsWith("-pid")) {&lt;br/&gt;                // The '-pid' and option will let you specify the PID of the&lt;br/&gt;&lt;br/&gt;                // target VM you want to connect to. It will then use the &lt;br/&gt;                // attach API to dynamically launch the JMX agent in the target&lt;br/&gt;                // VM (if needed) and to find out the JMXServiceURL of the&lt;br/&gt;&lt;br/&gt;                // the default JMX Connector in that VM.&lt;br/&gt;                //&lt;br/&gt;                    if (serviceURL != null)&lt;br/&gt;&lt;br/&gt;                        throwSyntaxError("-url and -pid are mutually exclusive");&lt;br/&gt;                    if (port &amp;gt; 0)&lt;br/&gt;                        throwSyntaxError("-port and -pid are mutually exclusive");&lt;br/&gt;&lt;br/&gt;                    if (++i &amp;gt;= args.length)&lt;br/&gt;                        throwSyntaxError("missing pid after -pid");&lt;br/&gt;                    try {&lt;br/&gt;&lt;br/&gt;                        pid = args[i];&lt;br/&gt;                    } catch (Exception x) {&lt;br/&gt;                        throwSyntaxError("bad pid after -pid: " + x);&lt;br/&gt;&lt;br/&gt;                    }&lt;br/&gt;                } else if (args[i].startsWith("-help")) {&lt;br/&gt;                    final List&amp;lt;String&amp;gt; vmlist = new ArrayList();&lt;br/&gt;&lt;br/&gt;                    for (VirtualMachineDescriptor vd : VirtualMachine.list()) {&lt;br/&gt;                        vmlist.add(vd.id());&lt;br/&gt;                    }&lt;br/&gt;                    System.err.println(SYNTAX);&lt;br/&gt;&lt;br/&gt;                    System.err.println("Running JVMs are: "+vmlist);&lt;br/&gt;                    throw new IllegalArgumentException(SYNTAX);&lt;br/&gt;&lt;br/&gt;                } else {&lt;br/&gt;                    throwSyntaxError("Unknown argument: "+args[i]);&lt;br/&gt;                } &lt;br/&gt;            }&lt;br/&gt;            &lt;br/&gt;&lt;br/&gt;            // A JMXServiceURL was given on the command line, just use this.&lt;br/&gt;            //&lt;br/&gt;            if (serviceURL != null)&lt;br/&gt;&lt;br/&gt;                return serviceURL;&lt;br/&gt;            &lt;br/&gt;            // A -host -port info was given on the command line. &lt;br/&gt;            // Construct the default RMI JMXServiceURL from this.&lt;br/&gt;&lt;br/&gt;            //&lt;br/&gt;            if (port &amp;gt; 0) {&lt;br/&gt;                if (host == null)&lt;br/&gt;                    host = "localhost";&lt;br/&gt;&lt;br/&gt;                &lt;br/&gt;                try {&lt;br/&gt;                    return new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+&lt;br/&gt;&lt;br/&gt;                            host+":"+port+"/jmxrmi");&lt;br/&gt;                } catch (Exception x) {&lt;br/&gt;                    throwSyntaxError("Bad host or port number: "+x);&lt;br/&gt;&lt;br/&gt;                }&lt;br/&gt;            }&lt;br/&gt;            &lt;br/&gt;            // A PID was given on the command line. &lt;br/&gt;            // Use the attach API to find the target's connector address, and&lt;br/&gt;&lt;br/&gt;            // start it if needed.&lt;br/&gt;            //&lt;br/&gt;            if (pid != null) {&lt;br/&gt;                try {&lt;br/&gt;&lt;br/&gt;                    return getURLForPid(pid);&lt;br/&gt;                } catch (Exception x) {&lt;br/&gt;                    throwSyntaxError("cannot attach to target vm "+pid+": "+x);&lt;br/&gt;&lt;br/&gt;                }&lt;br/&gt;            }&lt;br/&gt;            &lt;br/&gt;            final List&amp;lt;String&amp;gt; vmlist = new ArrayList();&lt;br/&gt;            for (VirtualMachineDescriptor vd : VirtualMachine.list()) {&lt;br/&gt;&lt;br/&gt;                vmlist.add(vd.id());&lt;br/&gt;            }&lt;br/&gt;            throwSyntaxError("missing argument: "+ "-port | -url | -pid | -list"&lt;br/&gt;&lt;br/&gt;                    +"\n\tRunning VMs are: "+vmlist);&lt;br/&gt;            &lt;br/&gt;            // Unreachable.&lt;br/&gt;            return null;&lt;br/&gt;&lt;br/&gt;        }&lt;br/&gt;        &lt;br/&gt;        &lt;br/&gt;        private void throwSyntaxError(String msg) {&lt;br/&gt;            System.err.println(msg);&lt;br/&gt;            System.err.println(SYNTAX);&lt;br/&gt;&lt;br/&gt;            throw new IllegalArgumentException(msg);&lt;br/&gt;        }&lt;br/&gt;&lt;br/&gt;        private JMXServiceURL getURLForPid(String pid) throws Exception {&lt;br/&gt;&lt;br/&gt;            &lt;br/&gt;            // attach to the target application&lt;br/&gt;            final VirtualMachine vm = VirtualMachine.attach(pid);&lt;br/&gt;            &lt;br/&gt;            // get the connector address&lt;br/&gt;&lt;br/&gt;            String connectorAddress =&lt;br/&gt;                    vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS);&lt;br/&gt;            &lt;br/&gt;            // no connector address, so we start the JMX agent&lt;br/&gt;&lt;br/&gt;            if (connectorAddress == null) {&lt;br/&gt;                String agent = vm.getSystemProperties().getProperty("java.home") +&lt;br/&gt;&lt;br/&gt;                        File.separator + "lib" + File.separator + "management-agent.jar";&lt;br/&gt;                vm.loadAgent(agent);&lt;br/&gt;                &lt;br/&gt;&lt;br/&gt;                // agent is started, get the connector address&lt;br/&gt;                connectorAddress =&lt;br/&gt;                        vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS);&lt;br/&gt;                assert connectorAddress != null;&lt;br/&gt;&lt;br/&gt;            }&lt;br/&gt;            return new JMXServiceURL(connectorAddress);&lt;br/&gt;        }&lt;br/&gt;        &lt;br/&gt;    }&lt;br/&gt;    &lt;br/&gt;    /**&lt;br/&gt;     * @param args the command line arguments: &lt;br/&gt;&lt;br/&gt;     *             must be -url &amp;lt;jmx-url&amp;gt;,&lt;br/&gt;     *             or -port &amp;lt;port-number&amp;gt; [-host &amp;lt;host-or-ip],&lt;br/&gt;     *             or -pid &amp;lt;pid&amp;gt;,&lt;br/&gt;     *             or -help&lt;br/&gt;     */&lt;br/&gt;    public static void main(String[] args) throws Exception {&lt;br/&gt;&lt;br/&gt;        // Parse arguments.&lt;br/&gt;        final ConnectionArgs cArgs = new ConnectionArgs(args);&lt;br/&gt;        &lt;br/&gt;        // Get target's URL&lt;br/&gt;&lt;br/&gt;        final JMXServiceURL target = cArgs.getJMXServiceURL();&lt;br/&gt;        &lt;br/&gt;        // Connect to target (assuming no security)&lt;br/&gt;        final JMXConnector connector = JMXConnectorFactory.connect(target);&lt;br/&gt;&lt;br/&gt;        &lt;br/&gt;        // Get an MBeanServerConnection on the remote VM.&lt;br/&gt;        final MBeanServerConnection remote = &lt;br/&gt;                connector.getMBeanServerConnection();&lt;br/&gt;&lt;br/&gt;        &lt;br/&gt;        final RuntimeMXBean remoteRuntime = &lt;br/&gt;                ManagementFactory.newPlatformMXBeanProxy(&lt;br/&gt;                    remote,&lt;br/&gt;                    ManagementFactory.RUNTIME_MXBEAN_NAME,&lt;br/&gt;&lt;br/&gt;                    RuntimeMXBean.class);&lt;br/&gt;        &lt;br/&gt;        System.out.println("Target VM is: "+remoteRuntime.getName());&lt;br/&gt;        System.out.println("Started since: "+remoteRuntime.getUptime());&lt;br/&gt;&lt;br/&gt;        System.out.println("With Classpath: "+remoteRuntime.getClassPath());&lt;br/&gt;        System.out.println("And args: "+remoteRuntime.getInputArguments());&lt;br/&gt;&lt;br/&gt;        connector.close();&lt;br/&gt;    }&lt;br/&gt;    &lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5030911595679452622-5676963973282828010?l=blogblowbando.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blogblowbando.blogspot.com/feeds/5676963973282828010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5030911595679452622&amp;postID=5676963973282828010' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/5676963973282828010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/5676963973282828010'/><link rel='alternate' type='text/html' href='http://blogblowbando.blogspot.com/2009/06/how-to-monitor-remote-jvm.html' title='How to Monitor Remote JVM'/><author><name>Supratim Bandyopadhyaya</name><uri>http://www.blogger.com/profile/18354782392378655303</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5030911595679452622.post-3350237249389209542</id><published>2008-02-11T22:58:00.000-08:00</published><updated>2008-04-02T06:39:44.896-07:00</updated><title type='text'>Free Record your favourite TV programs and Movies. The Open Source Linux Way!</title><content type='html'>&lt;span style="color: rgb(51, 0, 51);font-family:verdana;" &gt;So, We have IPL cricket series coming up&lt;br /&gt;and you can't find a way to watch them because you&lt;br /&gt;work in shift? Or, you have a computer at home and&lt;br /&gt;you are looking for the most cost effective way of&lt;br /&gt;recording your favourite TV shows&lt;br /&gt;(be it NBA Baseball or race for NASCAR or clowning at WWE)&lt;br /&gt;&lt;br /&gt;   You have come to the right place my friend!&lt;br /&gt;If you don't have much time you can jump to the "Let's get started"&lt;br /&gt;section.&lt;br /&gt;&lt;br /&gt;Long ago there was a time when I spent lonely hours tweaking&lt;br /&gt;and turning all the stones to get a perfect recording from a windows&lt;br /&gt;based system. I was using the software that came with my tv card.&lt;br /&gt;My TV tuner is an old one from Pinnacle. It has one of those nice&lt;br /&gt;saa7134 Philips chips and records entirely in software.&lt;br /&gt;Usual VCD recording was okay, but the problem started&lt;br /&gt;when I went for a DVD quality recording. The software based&lt;br /&gt;encoder was a CPU hog. It ate up almost 75-80 % of my CPU&lt;br /&gt;clogging down my system. And when I thought about MPEG4&lt;br /&gt;quality, guess what, sometimes the program started to freeze.&lt;br /&gt;Even I lowered the resolution of the video, still audio video&lt;br /&gt;sync was a major problem. I couldn't even encode audio part of&lt;br /&gt;the signal as mp3(using LAME). It just wouldn't record in any&lt;br /&gt;other format except wav. And windows is notorious for its&lt;br /&gt;clumsy driver model and slow framerate. There are so many&lt;br /&gt;layers of abstraction in Windows directshow that when a problem&lt;br /&gt;occurs (like with Smart Tee filter outputs extreme low resolution&lt;br /&gt;video while recording) it is just nearly impossible for a simple&lt;br /&gt;user like me to understand the cause and troubleshoot.&lt;br /&gt;&lt;br /&gt; In those days Linux still had 2.4x kernel and did not&lt;br /&gt;support by TV card out of the box. It was a painful process&lt;br /&gt;of recompiling the kernel with a custom hack (patch) to get&lt;br /&gt;my card working properly with any distribution. But then&lt;br /&gt;came the Next Generation Kernel 2.6x&lt;br /&gt;This was a major leap forward in hardware support&lt;br /&gt;(we wouldn't dig much deep into it as it's way out of scope).&lt;br /&gt;So I downloaded the most talked about distribution of the time&lt;br /&gt;SuSe 10.2 32bit x86 DVD distribution. Man, this thing rocks!&lt;br /&gt;Right form the installation with those fancy GUI installer,&lt;br /&gt;to the configuration with Yast which is virtually THE tool&lt;br /&gt;for a system wide common configuration  I didn't feel the pain&lt;br /&gt;of configuring a tidy linux box. And here is the best part, my TV&lt;br /&gt;card worked out of the box.&lt;br /&gt;&lt;br /&gt;The next thing was to set up a recording station to record&lt;br /&gt;my favourite show. The best thing about this is, it's all free and&lt;br /&gt;legal, if you do not copy copywrited material(mostly movies).&lt;br /&gt;&lt;br /&gt;     This is where we will begin describing the process of configuring&lt;br /&gt;your linux box (with a supported TV card) as a TIVO like&lt;br /&gt;PVR. Fasten your seat belts!!&lt;br /&gt;&lt;br /&gt;Let's get started:&lt;br /&gt;&lt;br /&gt;Things that we will need are the following.&lt;br /&gt;&lt;br /&gt;1: mplayer with mencoder (you can download source and compile it)&lt;br /&gt;   or you may install packed binary released for your distribution.&lt;br /&gt;&lt;br /&gt;2: open up the terminal and type&lt;br /&gt;&lt;br /&gt;                  ls /proc/acpi&lt;br /&gt; and hit enter. See if you can find an item in the list that says&lt;br /&gt;               alarm&lt;br /&gt; if you do, we will possibly be able to poweron and poweroff&lt;br /&gt; the system for automatically when we need to record something.&lt;br /&gt;&lt;br /&gt;3: Last but not the least, you need a lot of freespace as video recording&lt;br /&gt; is a space consuming task&lt;br /&gt;&lt;br /&gt;  First install the mplayer and mencoder as root.&lt;br /&gt;&lt;br /&gt; now, if you have only one TV card in your computer&lt;br /&gt; you will find it under /dev/video0 configured as&lt;br /&gt;  a V4L device. We can write the following&lt;br /&gt; command to check if the TV card is working.&lt;br /&gt;&lt;br /&gt;mplayer tv:// -tv driver=v4l2:input=0:norm=pal:width=640:height=480:device=/dev/video0:\&lt;br /&gt;freq=775.25:adevice=/dev/dsp1:forceaudio:audiorate=32000&lt;br /&gt;&lt;br /&gt;If there is no sound  check the followings.&lt;br /&gt;&lt;br /&gt;1:Check your loopback audio cable from the TV card sound out, see if it is connected to&lt;br /&gt;the Line In of the sound card.&lt;br /&gt;2: From alsamixer or kmix or any other sound mixer unmute the line in and increase&lt;br /&gt;the sound.&lt;br /&gt;&lt;br /&gt;you can use "h" and "k" to browse the other channels.&lt;br /&gt;&lt;br /&gt;Now we will record a test video.&lt;br /&gt;&lt;br /&gt;Now become root or sudo and perform the following steps.&lt;br /&gt;&lt;br /&gt;Copy this script to a file named vcrui.sh&lt;br /&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;ROOT_UID=0&lt;br /&gt;NARGS=1&lt;br /&gt;&lt;br /&gt;if [ "$UID" -ne "$ROOT_UID" ]&lt;br /&gt;then&lt;br /&gt;&lt;br /&gt;echo "You must be root to record a program"&lt;br /&gt;exit $E_NOTROOT&lt;br /&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if [ $# -ge  "$NARGS" ]&lt;br /&gt;&lt;br /&gt;then&lt;br /&gt;&lt;br /&gt;echo "Feature Not Implemented"&lt;br /&gt;&lt;br /&gt;exit $E_NO_ARGS_SUPPORTED&lt;br /&gt;&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;echo "Enter channel number::"&lt;br /&gt;read xnumber&lt;br /&gt;echo "Enter Program Name::"&lt;br /&gt;read xname&lt;br /&gt;echo "Enter duration in Seconds::"&lt;br /&gt;read xduration&lt;br /&gt;&lt;br /&gt;exec ./vr.sh $xnumber $xduration $xname /LinuxBackup/TV/&lt;br /&gt;# EOF&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And create another script file named vr.sh&lt;br /&gt;with the following codes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;if [ $# -le 2 ]&lt;br /&gt;then&lt;br /&gt;    echo "Usage: $0 channel seconds title optional-&gt;&gt;path"&lt;br /&gt;    exit&lt;br /&gt;fi&lt;br /&gt;rmmod saa7134&lt;br /&gt;modprobe saa7134&lt;br /&gt;&lt;br /&gt;FIL=$(date +%F_%H%M)\_$1$3&lt;br /&gt;&lt;br /&gt;WIDTH=352&lt;br /&gt;HEIGHT=264&lt;br /&gt;MENCODER=/usr/local/bin/mencoder&lt;br /&gt;AUDIO="-oac mp3lame -lameopts cbr:br=128:mode=3"&lt;br /&gt;VIDEO="-ovc lavc -lavcopts vcodec=mpeg4:mbd=2:vbitrate=700:aspect=4/3"&lt;br /&gt;DSP="adevice=/dev/dsp"&lt;br /&gt;TV=" -tv driver=v4l2:width=$WIDTH:height=$HEIGHT:outfmt=yuy2:device=/dev/video0:input=0:norm=PAL:chanlist=europe-west:channel=$1:$DSP"&lt;br /&gt;$MENCODER tv:// $TV $VIDEO $AUDIO -endpos $2 -ffourcc divx -o  "$4$FIL.avi"&lt;br /&gt;&lt;br /&gt;sync&lt;br /&gt;&lt;br /&gt;exit&lt;br /&gt;&lt;br /&gt;Now, change the file type of both of the script files to executable.&lt;br /&gt;&lt;br /&gt;chmod +x *.sh&lt;br /&gt;&lt;br /&gt;now create the following folder path if it does not exist&lt;br /&gt;&lt;br /&gt;/LinuxBackup/TV/&lt;br /&gt;&lt;br /&gt;the command is&lt;br /&gt;mkdir -p /LinuxBackup/TV/vcr&lt;br /&gt;&lt;br /&gt;now open up the recording wizard with the following command&lt;br /&gt;&lt;br /&gt;./vcrui.sh&lt;br /&gt;&lt;br /&gt;and follow the wizard and record a 2 minutes video.&lt;br /&gt;&lt;br /&gt;play the video with mlayer.&lt;br /&gt;&lt;br /&gt;Now we will setup an automatic recording with the tool&lt;br /&gt;&lt;br /&gt;NU-Tcron&lt;br /&gt;&lt;br /&gt;Go to the following website http://supratim.nonlogic.org and download it&lt;br /&gt;&lt;br /&gt;once downloaded, extract and compile with the command  as root.&lt;br /&gt;&lt;br /&gt;./configure;make;make install;&lt;br /&gt;&lt;br /&gt;once installed start the service if it already has not started.&lt;br /&gt;(check the instructions inside the source archive for details on hibernate hooks&lt;br /&gt;. This is very important, otherwise it wouln't work properly)&lt;br /&gt;&lt;br /&gt;Now create the following recording script (it applies for suse)(check your&lt;br /&gt;distro for hibernate support and command)&lt;br /&gt;&lt;br /&gt;file vcr.sh&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;if [ $# -le 2 ]&lt;br /&gt;then&lt;br /&gt;    echo "Usage: $0 channel seconds title optional-&gt;&gt;path"&lt;br /&gt;    exit&lt;br /&gt;fi&lt;br /&gt;rmmod saa7134&lt;br /&gt;modprobe saa7134&lt;br /&gt;&lt;br /&gt;FIL=$(date +%F_%H%M)\_$1$3&lt;br /&gt;&lt;br /&gt;WIDTH=352&lt;br /&gt;HEIGHT=264&lt;br /&gt;MENCODER=/usr/local/bin/mencoder&lt;br /&gt;AUDIO="-oac mp3lame -lameopts cbr:br=128:mode=3"&lt;br /&gt;VIDEO="-ovc lavc -lavcopts vcodec=mpeg4:mbd=2:vbitrate=700:aspect=4/3"&lt;br /&gt;DSP="adevice=/dev/dsp"&lt;br /&gt;TV=" -tv driver=v4l2:width=$WIDTH:height=$HEIGHT:outfmt=yuy2:device=/dev/video0:input=0:norm=PAL:chanlist=europe-west:channel=$1:$DSP"&lt;br /&gt;$MENCODER tv:// $TV $VIDEO $AUDIO -endpos $2 -ffourcc divx -o  "$4$FIL.avi"&lt;br /&gt;&lt;br /&gt;sync&lt;br /&gt;&lt;br /&gt;pm-hibernate&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Once you create this and change permission to executable, go back to the terminal&lt;br /&gt;and type&lt;br /&gt;&lt;br /&gt;tcrontab -e&lt;br /&gt;&lt;br /&gt;and type in a command like the following&lt;br /&gt;&lt;br /&gt;15 7 30 3 * /bin/bash /LinuxBackup/vcr/vcr.sh 33 8100 Threshold /LinuxBackup/TV/&lt;br /&gt;&lt;br /&gt;a    b  c  d e    .....................    f ..............................       g  h            i               .......    j  ...................&lt;br /&gt;&lt;br /&gt;where  ....&lt;br /&gt;&lt;br /&gt;a is military hour (3 PM)&lt;br /&gt;b is minute&lt;br /&gt;c is day of the month&lt;br /&gt;d is month of the year&lt;br /&gt;e we don't need to mention so we put *&lt;br /&gt;f bash command for execution path of the vcr script&lt;br /&gt;(make sure you create vcr folder and copy vcr.sh into it)&lt;br /&gt;g channel number&lt;br /&gt;h record how many seconds&lt;br /&gt;i a name of the program&lt;br /&gt;j archival path of the video ( a partition with a lot of free space)&lt;br /&gt;&lt;br /&gt;with this settings a full length 2 hour movie would take&lt;br /&gt;almost 700mb (a CD)&lt;br /&gt;&lt;br /&gt;If you have set up NU-Tcron properly, you can now hibernate&lt;br /&gt;(Please don't turn off the power supply)&lt;br /&gt;your linux box. It will automatically wake up the movie and&lt;br /&gt;go back to hibernation.&lt;br /&gt;&lt;br /&gt;              So, never miss a single movie on TV. I also have some info&lt;br /&gt;on how to setup the whole thing with automatically downloaded&lt;br /&gt;EPG from the internet and record your favourite movies on the&lt;br /&gt;basis of IMDB rating. But that's another story. Check back to my&lt;br /&gt;website and I will post that also, soon( If I find some time).&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5030911595679452622-3350237249389209542?l=blogblowbando.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://blogblowbando.blogspot.com/feeds/3350237249389209542/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5030911595679452622&amp;postID=3350237249389209542' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/3350237249389209542'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5030911595679452622/posts/default/3350237249389209542'/><link rel='alternate' type='text/html' href='http://blogblowbando.blogspot.com/2008/02/this-is-hd-and-you-are-expected-to.html' title='Free Record your favourite TV programs and Movies. The Open Source Linux Way!'/><author><name>Supratim Bandyopadhyaya</name><uri>http://www.blogger.com/profile/18354782392378655303</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
