Thursday, April 2, 2009

Linux: How to use an external hard disk, how to mount it

Problem: In my case I plugged the external hard disk into the USB port; a new folder with the name of my external HD was created, but it was empty.

Solution: I had to mount by hand the external hard disk, even if it was automaticaly recognized and a folder for it (empty) was created.

----------

The problem was that, when I plugged my external HD to the USB port of my Linux box, the disk was recognized and a folder was created under /media/NewHD , but the folder was empty. NewHD is the label, the name, that I choose when I first formatted my new USB external disk.

To solve I followed these steps:

  1. You have to find the "dev" name of your external HD after you plugged it in:
    dmseg
    You will find something like these lines:

    Initializing USB Mass Storage driver...
    scsi6 : SCSI emulation for USB Mass Storage devices
    Vendor: SAMSUNG Model: HM251JI Rev:
    Type: Direct-Access ANSI SCSI revision: 02
    SCSI device sdc: 488397168 512-byte hdwr sectors (250059 MB)
    sdc: assuming drive cache: write through
    SCSI device sdc: 488397168 512-byte hdwr sectors (250059 MB)
    sdc: assuming drive cache: write through
    sdc: sdc1

    From the last line you know that your external drive was mapped by Linux to the /dev/sdc1

  2. You have to check if the external drive was actually mounted somewhere else:
    mount
    You get something like this:

    [root@hece02] /media $ mount
    /dev/mapper/VolGroup00-LogVol00_Root on / type ext3 (rw)
    none on /proc type proc (rw)
    none on /sys type sysfs (rw)
    none on /dev/pts type devpts (rw,gid=5,mode=620)
    usbfs on /proc/bus/usb type usbfs (rw)
    /dev/sda1 on /boot type ext3 (rw)
    none on /dev/shm type tmpfs (rw)
    /dev/mapper/VolGroup00-LogVol01_Home on /home type ext3 (rw)
    /dev/mapper/VolGroup00-LogVol02_Scratch on /localscratch type ext3 (rw)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
    AFS on /afs type afs (rw)

    If your /dev/sdc1 is present there, you know that you can access the content of your drive from the path associated with the /dev/sdc1. Otherwise keep following.

  3. You have to mount the external hard disk:
    mount /dev/sdc1 /media/NewHD

  4. And now you can access the content of your disk! :-)

When you have finished, you have to unmount it, before unplugging it from your Linux computer; something like the "Safely Removing" in Windows.
Just type:
umount /media/NewHD
then you can unplug it.

Python: Exception TypeError "argument of type 'instance' is not iterable" in 'garbage collection' ignored. Fatal Python error: unexpected exception

Problem: I got a nasty Fatal error message running my Python code: "Exception exceptions.TypeError: "argument of type 'instance' is not iterable" in 'garbage collection' ignored"

Solution: I forgot to use vars() function when checking the existance of a variable in an imported module

-----------------

I got this error in my Python code today, and it took me 20 minutes to understand where the bug was.

Actually the line number showed in the error message was false. The error itself started some lines above and it propagated until the incriminated line.

So this was the error:


Exception exceptions.TypeError: "argument of type 'instance' is not iterable" in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
Aborted


And the problem was an "IF" statement where I checked for a variable name in an imported module:

My "IF" was this:


if 'fileName' in myModule:
fileName = 'OutputFile_%s.py' % myModule.fileName


To fix the problem I had to correctly add "vars()", of course ;-)


if 'fileName' in vars(myModule):
fileName = 'OutputFile_%s.py' % myModule.fileName


The bug was very stupid, just forgot the "vars()" function. But it was not so easy to find because the error message Python gave was not so helpful.

Wednesday, April 1, 2009

Eclipse IDE: How to install and configure MinGW GNU C++ compiler for Windows

Eclipse IDE has the very nice CDT environment for C++ programming.

In order to use it under Windows, you have to install a C++ compiler.

Our suggestion is to install the MinGW compiler, "A MINimalistic Gnu for Windows" Gcc compiler.

Go to http://www.mingw.org/ and download the installer for Windows from here.

Then start the Installer and choose to install the basic package + the g77 compiler + Make for MinGW, as those are the tools needed for compiling C++ code with Eclipse... and not only with Eclipse ;-)

Once installed everything you have to add the MinGW path to your PATH environment variable, to make the compiler findable.

Let's say we have installed the MinGW package on C:\MinGW. Refer to the picture below.
You have to open Start --> Control Panel --> System. In the pop up window that appears select on the left side "Advanced System Settings" and then goes to the tab Advanced and choose "Environment Variables...". There look for the "Path" variable in the System Variables window below (look for PATH, instead, if you want to set the MinGW compiler only for you as user) and click on "Edit...". In the pop up window you'll find a long string to edit. Go to the end of that string line and add ";C:\MinGW\bin". Then "Ok" and again "Ok".





Now your new nice MinGW compiler is ready to be used.

To make a test open a new command prompt (Start --> All Programs --> Accessories --> Command Prompt) and try to type "mingw32-make --version". If everything worked fine you should see a window telling you the version of the newly installed package.

Now open your Eclipse IDE with CDT for C++. Eclipse now should see and should be able to use MinGW C++ compiler!! :-)

So...have fun programming C++! :-)

Eclipse: How to get rid of the squiggly orange line in C++ editor

Problem: Using the Eclipse IDE with C or C++ code I have an annoying orange squiggly line throughout my code

Solution: Changing the C/C++ Indexer Markers options


Using the Eclipse IDE to programming C++ code, when an "include file" statement is not resolved, it is marked with an orange question mark and the whole code in the file we are editing are understriked with an orange squiggly line, as shown in the picture below.



It's really annoying, in particular when we are editing a file outside the real environment where the code will be compiled, and we already know that the included files are not physically joinable in that moment ;-)

So, in order to get rid of this squiggly orange line, just open the menu Window --> Preferences --> General --> Editors --> Text editors --> Annotations, look for the orange question mark symbol called "C/C++ Indexer Markers" and check out the "Text as" option, as shown in the figure below




In this way you can keep the orange question mark warning symbol in the Eclipse C++ editor, telling you that the "include file" statement is not working; but you can get rid of this annoying orange squiggly line, as shown in the figure below, and you get back a clean code! :-)

Friday, October 24, 2008

Subclipse error: Svn can't create tunnel. Configuring SVN+SSH connection on Windows Vista

Good morning!

Yesterday I wanted to install the beautiful Eclipse IDE on my new Windows Vista laptop. Everything went fine. I also installed Subclipse, the interface to the "Subversion" Version Control System, in order to access my code in the repositories on the remote machines of my Insitute.
Everything went fine again, but then, when I wanted to set up a SVN+SSH connection to checkout my code from the remote machine, I got this error:

The system cannot find the file specified.
svn: Can't create tunnel: The system cannot find the file specified.

Looking on Internet I found a solution for Windows XP, that I had to modify a little bit. Here the solution.

The problem is that you have to specify the path of your SSH client. You can use the classical PuTTY or Plink, but I prefer to use the TortoisePlink, the modified version of Plink contained in the excellent TortoiseSVN package. Using the TortoisePlink client you will be prompted for your username and password without opening an ugly CMD window (the command line window) every time.

So, let's say you have already installed the SVN client, you have now to modify the config file.
In Windows Vista this file is stored in the hidden folder

C:\Users\[username]\App Data\Roaming\Subversion

There you find the file named config. Open it with an editor (for instance Notepad) and look for the string

[tunnels]

this line must be uncommented (no hash # symbol at the beginning of the line). Then you have to modify the line below, to set the right path to your SSH client

# ssh = $SVN_SSH ssh

Let's say you installed the package TortoiseSVN at C:\Program Files\TortoiseSVN
so you can leave commented the line # ssh = $SVN_SSH ssh and you can add this line just below it:

ssh = C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe

Done!! :-)

Now you should be able to connect to your remote site with SVN through a secure SSH tunnelling connection.

And, as always, let me know if you have some problems! ;-)

Sunday, October 12, 2008

Finalmente risolto il problema di Windows Vista con la connessione di rete wireless

Erano mesi ormai che nella nuova casa avevo questo problema con Windows Vista: ogni tanto, senza ragione apparente, perdeva la connessione wireless. Magari per dieci ore tutto funzionava...poi all'improvviso...PUM! L'iconcina della rete mostrava una bella "X" rossa e non c'era piu' verso di far rivelare a Windows la rete wireless di casa. Cercando di fare il refresh delle reti disponibili, appariva semplicemente la scritta "no wireless networks found in range". Solo un hibernate o un restart del computer risolvevano il problema. La rete poteva "cadere" in un momento qualsiasi, dopo due minuti come dopo 3 ore, senza un motivo apparente.
E il problema non era del router, perche' con Windows XP la rete restava bella visibile e funzionante.

Oggi ho voluto spulciare un po' su Internet, e alla fine ho trovato la soluzione sul blog di un ragazzo norvegese, che qui ringrazio ;-)

http://www.catonett.com/blog/archives/194

Nei commenti al post ho poi scoperto il link alla pagina Microsoft ufficiale:

http://support.microsoft.com/kb/928233

In pratica bisogna modificare (aggiungere) una chiave del registro di sistema per far si che Vista non usi un impostazione di rete relativa al DHCP, il protocollo che assegna gli indirizzi di rete in modo dinamico ai computer che richiedono la connessione al router.

Ora ho provato a seguire la procedura descritta nei due post...vediamo se funziona!

Speriamo di si! ;-)

Friday, June 6, 2008

How to measure memory consumption of a program on Linux

The Linux operating system provide detailed information about memory processes use. You can use the ps or the top tools; or you canread information written on the /proc filesystem.

There you can find detailed information for every jobs running on your machine. You can get a list of the running jobs with:


ps -A

and then look, for example, into the file /proc/5995/status, where 5995 is the Job ID:

cat /proc/5995/status

VmSize: 7660 kB
VmLck: 0 kB
VmRSS: 5408 kB
VmData: 4204 kB
VmStk: 20 kB
VmExe: 576 kB
VmLib: 2032 kB

Thursday, May 15, 2008

Linux Fedora Core: How to set the mailing service of YUM Package Manager

To set the mailing notification system of the YUM Packages Manager on Fedora Core Linux systems (as SLC4) edit the file
/etc/sysconfig/yum-autoupdate

and uncomment and edit this line:
#YUMMAILTO="root"

YUM will send a notification email to root every time it update something. Mail messages sent to "root" are stored in the file /var/mail/root. simply open this file with an editor or with more or cat commands.

If you want to receive a notification email on a real e-mail box, you can add more addresses separated by coma, as for example:
YUMMAILTO=user@domain.com,"root"

Wednesday, May 7, 2008

list of file with full path with 'ls' in a shell

if you want a list of file with the full path, ready to be pasted in a txt file to be processed by a script, for example, you have to add $PWD to the path in 'ls';
e.g.:

ls -1 $PWD/*.root

will show you the list of all the files ending with .root with their full path.

Wednesday, January 23, 2008

VI editor: Search and Replace text

IMPORTANT! Before start changing your text file, please remember the commands to UNDO and REDO:


:u or :undo[n]
:red or :redo[n]

where "n" is the number of changes. The default value is "n=1".


With the command (in ESC mode):

:%s/foo/bar/gc

the active file will be searched for the pattern "foo" and replaced with "bar". For every replacement you'll be asked for a confirmation.

With

:%s/foo/bar/g

you won't be asked for a confirmation.

:%s/foo/bar/gi is case-insensitive
:%s/foo/bar/gI is case-sensitive

With ESC or "q" you terminate the searching.

Note that above we used the % symbol. This is a shortcut that means "from the first line to the end of file".

The "substitute" (:s) command accepts, before of itself, a range of lines, e.g.:


:28s/text1/text2/ only on line 28
:.s/text1/text2/ only on the current line
:.,20s/text1/text2/ from current to line 20
:1,$s/text1/text2/ from line 1 to the end of file
:%s/text1/text2/ over the whole file. Like 1,$


Morevore please notice that if you want to use special characters like [ you have to escape them, like:


:.,$s/lego/\[lego/gc


this command substitutes all the occurrences of "lego" with "[lego", from the current line to the end of file, asking for confirmation before each substitution.

IMPORTANT. Please notice that you have to escape symbols ONLY within the substituting text, not in the text you look for. E.g.:

:.,$s/(ciao)/\[\(ciao)\)\]/gc

substitutes "(ciao)" with "[(ciao)]".