Wednesday, March 10, 2010

simple python thread example

<span class="k">import</span> <span class="nn">time</span>
<span class="k">from</span> <span class="nn">threading</span> <span class="k">import</span> <span class="n">Thread</span>

<span class="k">def</span> <span class="nf">myfunc</span><span class="p">(</span><span class="n">i</span><span class="p">):</span>
<span class="k">print</span> <span class="s">"sleeping 5 sec from thread </span><span class="si">%d</span><span class="s">"</span> <span class="o">%</span> <span class="n">i</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">5</span><span class="p">)</span>
<span class="k">print</span> <span class="s">"finished sleeping from thread </span><span class="si">%d</span><span class="s">"</span> <span class="o">%</span> <span class="n">i</span>

<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mf">10</span><span class="p">):</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">myfunc</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">i</span><span class="p">,))</span>
<span class="n">t</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>



Thursday, February 25, 2010

find which linux os is running

uname -a

Linux fip 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

tail /etc/redhat-release

CentOS release 5.4 (Final)


extract a tgz or tar.gz

To extract the compressed tar archive target.tar.gz into the current working directory with:

gzip -dc target.tar.gz | tar xf -

If the file was compressed with bzip2 (i.e., .tar.bz2), you can substitute the bzip2 command for gzip.

If the archive was compressed with the UNIX compress command (archive ending in .Z) you can use:

zcat target.tar.Z | tar xf -



Monday, February 8, 2010

Solution : error opening installation log file VMware-viclient.exe

Step 1. set following environment variable

           TMP = C:\TEMP
           TEMP = C:\TEMP
Step 2.  put the executable file under directory where you don't have any space in directory name
ex. C:\TEMP


C:\Documents and Settings\user [This will not work]

- Mihir Patel

Friday, February 5, 2010

how to extract tar.gz

tar xvf gzip-1.2.4.tar


Solution : configure.in: required file `./ylwrap' not found

Problem:

configure.in: required file `./ylwrap' not found
configure.in: `automake --add-missing' can install `ylwrap'

Solution :

copy in the ylwrap file from the automake1.10 directory to your local folder manually.

- Mihir Patel

Thursday, February 4, 2010

Ubuntu 9.10 + setting up auto detect proxy to correct apt-get update

if you can access google from firefox but unable to do apt-get update and install and stuff this article will help.


-- getting the proxysettings


  1. in the url type wpad/wpad.dat 
  2. save and open the wpad.dat file.
  3. you should see some thing like

function FindProxyForURL(url, host)
{
        if (isPlainHostName(host) ||
        isInNet(host, "10.0.0.0", "255.0.0.0") ||
        dnsDomainIs(host, ".pth.au.asap") ||
        dnsDomainIs(host, "sharepoint.site.com.au") ||
        dnsDomainIs(host, ".bne.au.asap") ||
        dnsDomainIs(host, ".talent2ehr.com") ||
        dnsDomainIs(host, ".hellobris") ||
        dnsDomainIs(host, ".wa") ||
        dnsDomainIs(host, ".switch.aust.com") ||
        dnsDomainIs(host, "HS9.site.com") ||
        dnsDomainIs(host, "inxsoftware.com") ||
        dnsDomainIs(host, "10.10.11.2") ||
    dnsDomainIs(host, ".csee-transport.fr") ||
        dnsDomainIs(host, "127.0.0.1"))
                return "DIRECT";
    if (shExpMatch(url, "http://155.89.236.87*")) {return "PROXY proxylu1.global.sys:3128";}
    if (shExpMatch(url, "http://155.89.1.145*")) {return "PROXY proxylu1.global.sys:3128";}
    if (shExpMatch(url, "http://155.89.1.131*")) {return "PROXY proxylu1.global.sys:3128";}
        else
                return "PROXY 10.25.41.14:3128; DIRECT";
    }

4. grab your proxy settings for it and enter then in the following tutorial.

- Mihir





===========================


Are you trying to use apt-get or synaptic or adept or {package-manager-of-choice} to keep Debian or Ubuntu machines up to date? Are you stuck behind your employer’s firewall? Is that firewall a Microsoft ISA proxy? Gee, you must be frustrated.

Our MS proxy speaks NTLM for authentication, and no amount of setting the http_proxy environment variable or rewriting /etc/apt/apt.conf seems to make any difference; the Linux machines can’t get out to the outside world.

Well, they partly can. Set the proxy details in Firefox and web browsing is fine, but nothing else is.

So, enter a very useful little Python application called ntlmaps or NTLM Authenticating Proxy Server. Set this up on a machine that needs updating, edit your /etc/apt/apt.conf to point to it, and away you go.

A few caveats. If you’re running Ubuntu, you should grab the ntlm package from Ubuntu — ntlmaps. If you’re on Debian you can get it from Debian’s page and of course it may be downloaded from its own site. I’d suggest not using the Debian one on Ubuntu or the Ubuntu one on Debian unless you want to fiddle endlessly with Python versions. But who would be silly enough {ahem} to do that?

I have had mixed experiences with using ntlmaps. First of all, I have seen suggestions that all you need to do is:

apt-get update
apt-get install ntlmaps

Yeah, nice one. Install via the network the thing you need to install things via the network. Sheesh. That’s why it’s necessary to use another machine to grab the .deb package from one of the providers I mentioned above and install it with a:

dpkg -i name_of_downloaded_package.deb

The install should finish with a nice series of questions designed to configure the proxy for you.

If it installed properly…

ps aux | grep ntl

…should show you the details of the running proxy.

You should be able to control the proxy via:

/etc/init.d/ntlm start
/etc/init.d/ntlm stop
/etc/init.d/ntlm restart

But on one of my machines these all failed silently and the ps aux | grep ntl revealed no running proxy. I ended up having to copy the /etc/ntlm/server.conf file to /usr/lib/site-python/ntlm/ directory and run:
sudo python /usr/lib/site-python/ntlm/main.py &
to backdoor the thing into going.

Update: Ignore my convoluted and painful hackaround above. The sane way to get ntlmaps working is to realise that there is a bug in the Debian and Ubuntu packages and to do this after you install it:

sudo dpkg-reconfigure ntlmaps

This will re-run the setup script and this time ask you all of the questions you need to answer to actually get it working. I have reported this bug via Ubuntu’s launchpad so with any luck the future releases may have this sorted out so you won’t need to re-run the config script after initially installing.

Oh, and make sure to edit (or create if it doesn’t exist) your /etc/apt/apt.conf so it contains:

ACQUIRE {
http://proxy "http://127.0.0.1:5865/"
}

Update update: I see that more recent installations of the apt system no longer have something called /etc/apt/apt.conf to manage their apt setup. This has been replaced by a directory called /etc/apt/apt.conf.d. So to get the proxy working on a newer setup, create a file called /etc/apt/apt.conf.d/proxy and put the above ACQUIRE stuff in it. Or like this if you wish:

Acquire::http::Proxy "http://127.0.0.1:5865/";

Port 5865 is the default port for the ntlmaps to listen on. If the planets are all in line, you should now be able to:

sudo apt-get update
or perhaps even better…
sudo aptitude update (aptitude apparently does a better job than apt-get)

Easy, eh? :-)

By the way, if your organisation has a password rotation policy that sees you changing your Windows login password with any sort of regularity, beware of being ambushed by ntlmaps. You will have given ntlmaps a password and it will keep using it. When you change your login password, be sure to reconfigure ntlmaps with your new one or it will silently continue authentication attempts via your user name and your old password. You may be happily logged in on another machine while ntlmaps quietly manages to get your account locked out. Hilarity ensues… or so I’m told.



Monday, January 11, 2010

Install Bugzilla on Ubuntu

A few  nights ago I attempted to install Bugzilla on a Ubuntu 8.10 test machine but I ran into a few snags. The Ubuntu team does a great job of packaging Bugzilla and setting it up with a nifty little installer, but for some reason I couldn't get it working. After a lot of searching around on Google and the Ubuntu forums, I finally found the last few bits of information to get Bugzilla working on my test machine. Since I know that several people out there are probably having a similar experience to mine, I decided to post a quick tutorial.

Starting the Installation

To get going, you simply need to issue the following command:

sudo apt-get install bugzilla3

This will grab Bugzilla and all the packages required to make Bugzilla work. If you have never installed MySQL before, the first dialog you will be greeted with is the one shown below. This is the step to set the "root" password for MySQL. Just make sure you pick a secure password and don't forget it! When you are done, click "Forward" to move on to the next step.

bug_1

 

The next dialog window you will see is the one shown below. This dialog is simply asking if you would like help configuring your database, so just click "Forward" to move on to configuring Bugzilla.

bug_1_5

 

For this step you will need the password for your MySQL database server. More specifically, you need the password for the administrative user "root"  (this is the password you entered in the first step) so that the installation program can install the default databases for you .
bug_3

 

The next step is to enter a password for the Bugzilla program to use. This is simply the password that is used by Bugzilla to interact with the MySQL database. If you don't want to make up a password for this step, you can just hit "Forward" and the installer will generate a password for you and store it in /etc/bugzilla3/localconf.

bug_4

 

Next you will see the dialog window shown below. This window is asking for information that will be used in your base Bugzilla install. The important thing to remember here is that you need to enter a valid e-mail address ( something@something.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it ). If you don't enter a proper address, you have to restart the installation from the beginning (something I learned the hard way). Once you have completed the form, click "Forward" to finish the installer.

bug_2

 

A Few Extra Tweaks

Now that you have the base install out of the way, you need to tweak a few files to get everything working. The first step is to copy the example Bugzilla configuration file to the Apache configuration folder. This can be done with the following command:

sudo cp /usr/share/bugzilla3/debian/apache.conf /etc/apache2/conf.d/bugzilla3.conf

This will setup Apache to point to the correct directories and libraries for Bugzilla. Once the file has been copied, restart Apache by issuing the following command:

sudo /etc/init.d/apache2 restart

The final step is to make sure that the Bugzilla parameter file is readable by Apache. This can be done with the following commands:

chmod g+rw /etc/bugzilla3/params

chown www-data:www-data /etc/bugzilla3/params

If all goes well you should be able to browse to your server (http://your_server_name/cgi-bin/bugzilla3) and see the Bugzilla login page. Now you are ready to login and get to smashing bugs!


If It Doesn't Work

If you follow all of these steps and Bugzilla still isn't working, your best option is to watch the Apache error log while you attempt to connect to the Bugzilla main page. You can do this by using the tail command to watch the log:

tail -f /var/log/apache2/error.log

Good luck!


ref : Jarrod Hyder (http://www.hacksawlabs.com)



Wednesday, January 6, 2010

Solution : JUNIT Setup \ 'java.lang.NoClassDefFoundError' error +Class not found "junit.samples.AllTests"

Follow the given steps:

  1. Download the Junit from the sourceforge repository.(Download Link) , the Zip file
  2. extract the zip file to a directory. ex c:\
  3. it should look like c:\junit4.8.1\ with folders ex. doc, javadoc etc
  4. Add the paths 
    • JUNIT_HOME=c:\junit4.8.1
    • CLASSPATH=c:\junit4.8.1\junit-4.8.1.jar;c:\junit4.8.1
  5. open a new command window
  6. go to the C:\junit4.8.1 folder
  7. try following java junit.textui.TestRunner junit.samples.AllTests
.........................................
.........................................
.........................................
.......
Time: 0.453
OK (130 tests)


else try running the command line version

C:\junit4.8.1>java -classpath "C:\junit4.8.1\junit-4.8.1.jar;c:\junit4.8.1" junit.textui.TestRunner junit.samples.AllTests

Output should be like below

.........................................
.........................................
.........................................
.......

Time: 0.422
OK (130 tests)

if this does not work that means you may be using wrong java version. (I have tested junit 4.8.1 working with JDK 5)

- Mihir Patel.

How to setup JAVA_HOME environment variable in Windows

Please follow the instructions to set up JAVA_HOME environment variable in your computer. First find out the installation folder of Java development kit (JDK) in your machine. Let's assume it is installed in the folder "C:/j2sdk1.4.2"

  1. Right click on the My Computer icon on your desktop and select properties
  2. Click the Advanced Tab
  3. Click the Environment Variables button
  4. Under System Variable, click New
  5. Enter the variable name as JAVA_HOME
  6. Enter the variable value as the install path for the Development Kit
  7. Click OK
  8. Click Apply Changes


Ref : http://wso2.org/project/wsas/java/1.1/docs/setting-java-home.html