Author Archives: Abdullah Chougle

Unlist Your Number from TrueCaller today!

UPDATE July 18, 2013: Approximately 7 months after this article was published, there’s been news that the TrueCaller database has been hacked into by the so-called Syrian Electronic Army. Again, this highlights the need for users to be careful in the choosing the companies with whom they entrust their private data.

TrueCaller is a mobile app and online service that serves as a very large phonebook for reverse phone number lookups. It can be used to augment your own phone’s contact list in your iOS, Android, Windows Phone, Symbian, or BlackBerry device, helping you let know the names of unknown callers. You can test to see which of your or your friends’ numbers are available in their database at www.truecaller.com.

How does it work?

TrueCaller claims to source the caller information present in their database partly from public directories, and partly from “crowdsourced” data.

However, when I checked, their data didn’t seem to come from public directories. I began searching for my friends’ landline and mobile numbers and those of my own as well, and noted a few interesting things:

  1. Sometimes somebody else’s name would prop up. This would probably be a previous owner, or the former name of the person in case of a name change.
  2. Sometimes the company name would be suffixed or prefixed to the name.

This definitely seems to be populated from contact lists of users.

TrueCaller seems to stop here – it doesn’t, for example, seem to retrieve or store users’ locations. Also, it doesn’t support searching by name – you can only search by number. However, what TrueCaller does reveal is still bad enough, and has actually made many users unhappy, as you can see in a Quora thread on this subject.

Removing your Number

Luckily, fixing this privacy issue turns out to be easy. Head over to Unlist your Phone Number to request an automatic unlisting of your number. It took a few hours for my numbers to get unlisted, and I heaved a sigh of relief after that.

Converting Multiple VMDK (Virtual Machine Disk) files into one

To convert multiple VMDKs into a single file, I used the following command (LinuxVM.vmdk is the name of the first VMDK file – i.e. the one attached to the VM):

$ vmware-vdiskmanager -r LinuxVM.vmdk -t 0 LinuxVMSingleDisk.vmdk

Note that vmware-vdiskmanager is bundled as part of VMware Workstation. I couldn’t locate that as a separate download, so I ended up downloading the trial version of Workstation.

The above operation takes a while, but not too long. It shows its progress as it completes.

Next, I had to modify the VM settings so that it would use the new disk. I couldn’t find this option in the GUI, so I had to modify the vmx file manually (use an appropriate editor on a Windows system):

$ vi LinuxVM.vmx

I modified the scsi0:0.fileName property to point to the new disk:

scsi0:0.fileName = "LinuxVMSingleDisk.vmdk"

Next, I double checked the VM settings in the GUI to check if the disk had changed, and then booted it up to confirm everything is fine. I then deleted all the old, multiple vmdk files.

The Motivation for Doing This

I’d been using a few heavy applications in my VM: an HTTP server, an Application Server behind it running a couple of large applications, and a database. When doing intensive work, my hard disk would make grinding noises and my Ubuntu host would suddenly exit to the login screen. I’d lose all data in my current session, though oddly, some background applications would continue to run.

So I decided to implement VMware’s suggestion to use a single file for better performance:

VMware Workstation - Creating a virtual disk

Did it really work? The host did crash once, but that was when another heavy application was running on the host itself. In my entirely subjective assessment, I do think there’s been an improvement in performance – though I still need to be a little careful with certain applications.

TCPMon – A Basic Tutorial

TCPMon is a nice little tool for testing TCP communication between a client and server. It is an open source project, distributed under the Apache 2.0 license.

Downloading and Running TCPMon

To download TCPMon, head over to the Apache TCPMon download page and download the binary distribution.

(There’s a Google Code Project called TCPMon too, but that’s not the same one, and has fewer features)

Once downloaded and extracted, navigate to the build folder and run TCPMon by executing tcpmon.sh on Linux or tcpmon.bat on Windows. (On Linux, you’ll need to set the execute bit on the sh file before you run it). Note that your current working directory must be the build folder, else Java will report a ClassNotFoundException

TCPMon as an intermediary between clients and a single server

I found TCPMon useful when testing a webservice client I was implementing – I wanted to be certain that it’s sending the right data, and also wanted to double check the server responses in a convenient way. Here’s what you need to do:

  1. Specify the listener properties. The listener port is any arbitrary port that you’d like TCPMon to listen to (and that any other process isn’t using). The target port is that of your webservice.
  2. Click Add

TCPMon admin tab - Configuring a listener

In the window that appears, you will be able to monitor connections between your client and server after setting up your client to point to TCPMon’s listening port. TCPMon forwards all requests to the target server, and you’ll be able to see the requests and responses as they occur.

Requests and responses in TCPMon

Checking the “XML Format” box adds appropriate indentation to any XML in subsequent requests and responses. This can make it easier to read.

TCPMon as a proxy server (an intermediary between clients and an outbound connection of the machine hosting TCPMon)

Another functionality is the use of TCPMon as a proxy – you can set up a proxy server on your machine using it, so that all requests from another device or machine are routed through the proxy.

I found this useful when testing on mobile devices that needed to connect to a VPN network accessible from my computer, but not from the device itself.

Here’s what you need to do to set up the proxy server:

Setting up a proxy server in TCPMon

To get a mobile device connected through this proxy, you’ll need to modify the proxy settings of your Wifi connection:

Setting up an iPad to connect to TCPMon

Now all requests from this device will be routed through the TCPMon proxy.

Note that TCPMon is useful only for simple testing of requests and responses – it fails to work on anything more than a small number of requests. You’ll need a dedicated proxy server for that.

Also, if you’re connecting to a single server, it’s best to go with the first approach of an intermediary rather than a proxy server, so that TCPMon doesn’t capture traffic you don’t need to inspect.

Sending custom requests

The “Sender” tab can be used to craft your own SOAP requests and send them. The fields under this tab are pretty self-explanatory:

Sending requests from TCPMon

– See more at: file:///C:/B/Backups/Technonstop/technonstop.com/tcpmon-tutorial.html#sthash.uvcYqRuS.dpuf

The Meaning of dot slash for Running an Executable in Linux

The dot refers to the current directory. The forward slash “/” is the directory path separator.

So, when you type in ./filename at the shell, you prefix the filename with the path to the current directory.

Why do we need to do this when running any executable file?

When you run a command in the shell, it either runs it as a built-in command, or as an executable.

If it isn’t a built-in command, the shell tries looking for the executable in all the directories specified by the PATH environment variable – you can see what this contains by typing in echo $PATH in the terminal.

So if your file is in the current directory, the shell won’t find it – because the current directory is not included in the PATH by default. If you prefix the dot and the slash, the path to the file is passed to the shell, which looks for it exactly at the specified location. In fact, the shell doesn’t search the PATH at all when an absolute or relative path (other than just the filename) is specified.

Here’s something to try, but make sure you immediately undo it by exiting the terminal: Add the current directory to the PATH variable in your current shell by typing in

export PATH=$PATH:.

Now, you can run your executable without the dot slash!

WARNING: As noted in the comments below, this change has security implications. The above command will last only for the current terminal session – the changes to the PATH variable will be lost when you exit the terminal. Make sure you do not make this change permanent.

How about using the absolute path?

Since the dot slash helps the shell find the executable by specifying the directory, providing the absolute path without the dot prefix also works.

People might think you always need the dot to be prefixed, even when using absolute paths, but that doesn’t work because you end up prefixing the path to the current directory in addition to the complete path.

Note that you can also execute files using a relative path, in the form of <sub-dir>/<executable>, for example.

Remotely Working Together on a Terminal Session in Linux

I often get a chance to work from home, and this has given me opportunities to look for ways to share sessions with my colleagues. Windows XP used to have the excellent NetMeeting tool, but I recently switched to Ubuntu and haven’t yet found an equivalent.

Yes, I’ve heard of VNC and used it a lot too, but I wasn’t happy with its remote desktop sharing performance. Ekiga is interoperable with NetMeeting calls, but doesn’t support screen sharing. Even Skype’s screen sharing does not seem to support remote screen controlling.

However, Linux’s power is at the command line, and this is true even in the case of remote sharing. So here comes screen to the rescue – this magical command allows you to flawlessly resume lost sessions and share them with multiple users at the same time.

Starting screen

Start screen using

screen -d -R session_tomcat

Replace session_tomcat with any other helpful name for the session you’re about to create.

Sharing your Session

Ask your friend to connect using (assuming they are logged in using the same user account):

screen -x session_tomcat

Now it’s simply magical. Multiple persons can type and work on the same terminal – it works best when you’re coordinating over the phone. Note that the dimensions of your terminal output will be the same for every user – to change it, press CtrlA and then capital F. This will make the screen output fit your current terminal size, and change it to that size for every connected user.

Detaching from a Screen Session

Important: To detach from the screen session so that you can resume later, simply close the window. If you type exit, you’ll end up terminating the screen session and the processes running within.

Why screen is better than nohup and tail

Here’s a comparison. Consider a hypothetical example in which you need to find a file that contains the word “cat” in its name. You know it will take long, so you run the following combination of commands:


$ nohup find / -name *cat* &
$ tail -f nohup.out

The nohup command is a request to not kill (nohup stands for “no hangup”) the process that you are just about to run in case you lose connection. The & at the end sends the process to the background, so that the prompt returns immediately. The tail -f follows the output of the command executed through nohup. If you do lose connection, simply run tail -f nohup.out again to see the running output.

To do the equivalent in a screen session, you’ll only need run the find command in an open screen session. If you need to reconnect after a lost connection, run screen -d -R <session_name> again, and you’ll be back in your session as though you never left it.

Far more neat, isn’t it? Of course, screen has much more to offer than being a simple replacement for nohup and tail -f. For example, it’s very easy to resume a CLI session running remotely – you’d simply reconnect without having to re-initialize.

Other Advanced Usages

CtrlA has a special meaning when running screen – it allows you to execute special screen commands.

To see the list of available commands, type CtrlA and then ?.

For example, one interesting feature of screen is its support for multiple windows. To create a window, type CtrlA and then c.

To switch to a window, use CtrlA and then the window number (from 0 to 9).

To see the list of available windows type CtrlA and then ".

The man page of screen reveals a great deal more to explore!

Which features of the screen command in Linux do you find the most useful?

List of Shortcuts for the Eclipse Java IDE

Here’s a cheat sheet of Eclipse shortcuts I’ve put together to help me work really fast with the IDE. The shortcuts have been categorized into two sections – one that most people know about, and another section that contains the lesser known ones. You should be able quickly scan through the first section, and learn any of the ones that you don’t currently know.

The second section might take longer, and you may want to bookmark this page for future reference.

Easy Shortcuts

Search in files

Use CtrlH to search in all files across the workspace or project.

Search Dialog in Eclipse Juno

Open Resource

CtrlShiftR opens a resource quickly – without the time it spends for indexing. This makes it especially fast when you’ve just opened a workspace, in comparison to the Open Type shortcut below.

Open Resource Dialog in Eclipse Juno

Open Type

Use CtrlShiftT to open a Java type.

Open Type Dialog in Eclipse Juno

While I prefer CtrlShiftR to search for files, CtrlShiftT works better if you want to search for Java classes or interfaces.

Open the Type Hierarchy

Use CtrlT to get a popup window with the type hierarchy for the type under your cursor.

Type hierarchy popup - Eclipse Juno

This is tremendously useful to see inherited types, sub-types, and implemented interfaces.

Press CtrlT again to toggle between super-types and sub-types.

Display members and inherited members

Pressing CtrlO displays the class members, pressing it again displays the inherited members too!

Eclipse class members popup

Focusing on the tooltip

Press F2 to get the tooltip for the item currently under the cursor.

F2 Tooltip Eclipse Juno

Correcting Indentation of Selected Text

Use CtrlI to correct indentation.

Debuggging

Use F5 to Step into, F6 to Step over, F7 to step out, and F8 to resume. See below for more shortcuts on debugging.

New File Wizard

Use CtrlN to start the new File Wizard.

New File Wizard - Eclipse Juno

Lesser Known Shortcuts

CtrlTab to Switch Between Windows

Go to General->Keys to see all shortcuts.

Setting Eclipse Juno shortcut for switching between editor windows

Change the binding of Next Editor and Previous Editor to use Tab instead of F6 – this makes it incredibly easy to switch between open editors. I often dislike changing keyboard shortcuts so that it’s easy to work on someone else’s machine too, but I couldn’t resist this one.

Cycle through tabs in the current view

Similar to the above, but still slightly different: Use CtrlPgUp and CtrlPgDn to switch between tabs in your current viewwithout showing you the complete list of available tabs.

Scroll without using the mouse

Use CtrlUp and CtrlDown to scroll, while keeping your cursor in the same position!

Move a line or lines

Use AltUp and AltDown to move selected lines, or the current line.

Jump to matching bracket

CtrlShiftP on a bracket, brace or parenthesis moves the cursor to its matching bracket, brace or parenthesis.

Progressively Select Blocks

Use ShiftAltUp / ShiftAltDown to progressive select blocks.

Find references

CtrlShiftG will find references to the item under the cursor.

Find declarations (Only C++/Javascript)

CtrlG finds declarations of the item under the cursor.

Open Declaration

F3 opens the declaration for the item under the cursor.

Find previous and next, based on selection

Use ShiftCtrlK and CtrlK to find the previous and next occurrences of the item under the cursor.

I had to set CtrlK for “Find next” in Preferences->General->Keys, but the shortcut for “Find previous” was there by default.

CamelCase Code Completion

If you have a class that has a VeryLongName, simply type VLN and press CtrlSpace to see VeryLongName as one of the suggestions.

Automatically Insert Braces and Semicolons at the correct position

This isn’t a shortcut – but a useful productivity boost. Setting semicolons and braces to be automatically inserted in the correct position allows you to type them in from anywhere but they actually appear at the end of the line. Escaping text in string literals is another useful option.

Eclipse Juno preferences - automatic insertion of braces and semicolons at correct position and escaping pasted strings

Quick Access Menu

Quickly access any menu, command, editor, etc by typing in Ctrl3 and then the initial letters of the item you want.

Eclipse Juno quick access menu

History

Use AltLeft and AltRight to navigate between your editor history items. This is equivalent to using the history icons on the toolbar.

Eclipse Juno history toolbar buttons

Quick Fix

Use Ctrl1 to get to the quick fix menu and quickly fix compile-time issues.

Eclipse Ctrl-1 quick fix menu

Debugging

Use CtrlR to run to the current line. Use CtrlShiftB to toggle a breakpoint. F11 debugs the last run program, while CtrlF11 runs it.

Refactoring

ShiftAltR renames an item and updates all references. Use ShiftAltL to extract code to a local variable, and ShiftAltM to move code to a method.

The Best of them all!

And finally, which one’s the greatest shortcut of all? Use CtrlShiftL to get a list of all available shortcuts!!

Eclipse Juno list of shortcuts

\

How to enable Java in Chrome and Firefox on Ubuntu

To enable Oracle’s Java plugin in your Linux browsers, just copy these lines into a script, and run it!

JAVA_HOME=/usr/lib/jvm/jdk1.7.0
MOZILLA_HOME=~/.mozilla
mkdir $MOZILLA_HOME/plugins
ln -s $JAVA_HOME/jre/lib/i386/libnpjp2.so $MOZILLA_HOME/plugins

Note: You may need to change the value of JAVA_HOME so that it correctly points to your installation of the JDK. 64-bit users will need to change the final line to:
ln -s $JAVA_HOME/jre/lib/amd64/libnpjp2.so $MOZILLA_HOME/plugins

If you’re a newbie, here’s how to run the script:

  1. Using your favorite editor, paste the contents of the script into a new file.
  2. Find out where Oracle Java is installed. This location has the directories “bin”, “lib”, and “jre”, among others. Replace the value of JAVA_HOME with the path to this folder, and save the file. This step applies if you’re using the JDK. If you’re only using the JRE, let JAVA_HOME point to the jre installation directory (which contains the folders “bin”, “lib” and “plugin”), and modify the last line in the script to remove “jre” from the path.
  3. Make the script executable, by typing in chmod +x <filename>
  4. Run the script using the command ./<filename>
  5. Restart your browser, and confirm your installation as shown in the next section

The above script will enable Java support in both Chrome/Chromium and Firefox, since they both use the ~/.mozilla/plugins directory to scan for available plugins.

Confirming Installation

After you’ve restarted your browser, if you see a message below detailing your installed Java version and operating system, you’ll know it’s working successfully.

You can also look up the address “about:plugins” in Chrome or Firefox to get the list of plugins installed in your browser.

Alternatively, look up Oracle’s How do I test whether Java is working on my computer? to confirm the version of Java your browser is using.

Troubleshooting

If you’re facing problems with your Java plugin not working correctly on certain sites, you might want to try updating Java to the latest version. Also, you could try switching to Oracle’s version (in case you’re running the OpenJRE or IBM’s JRE), since that’s what’s best supported on the web.

A Quick Tutorial to Set Up an NFS Server on Windows

Update (Nov 9, 2011): As noted in the comments below, Windows Services for UNIX Version (SFU) is no longer supported on Windows 7 and 2008. For these versions, try installing Cygwin with the optional nfs-server component. If you’re using Windows 2008, you can use the Server for NFS that comes built-in instead – in this case, most of the steps below should apply.

A few days ago, I needed to share a large folder present on a Windows server to access it from my local Ubuntu workstation. I initially used Samba, but my build script refused to recognize paths present in that share.

The solution was to use an NFS share – but this required a special setup on Windows. Even after a lot of searching on Google, I couldn’t easily find a guide that talked about how to get started with an NFS server on Windows quickly. Most articles I came across were only detailing information on NFS security, or some obscure command line options for tweaking NFS options – which shouldn’t be required when all you want is a simple share within your local, protected network.

So, here’s what to need to do if you need an NFS server enabled on Windows quickly, and mount it on your Linux box:

1) Download Windows Services for UNIX from Microsoft’s Download Center. Here’s the direct download link.

2) Run setup.exe from the extracted directory.

Welcome to the Microsoft Windows Services for UNIX Setup Wizard

3) Follow the prompts, until you reach the following screen:

Installation Options

Choose custom installation – since we’d like to only install the NFS server for sharing folders.

4) Choose the following three components to install:
(i) NFS -> Server for NFS
(ii) Authentication tools for NFS -> User Name Mapping
(iii) Authentication tools for NFS -> Server for NFS Authentication

Here’s a pictorial representation of the components you’ll need:

Selecting Components   Selecting Components

5) On the next screen, choose to change the behavior to case-sensitive, to provide full compatibility with UNIX programs

6) On the User Name Mapping screen, choose “Local User Name Mapping Server” and “Password and group files”:

User Name Mapping

7) Now, copy your passwd and group files from your UNIX/Linux distribution onto your Windows machine. For Ubuntu, these are located at /etc/passwd and /etc/group. Provide the paths to these files in the next screen:

User Name Mapping Configuration

8) Continue with the installation prompts until you finish.

Installation...

9) Windows Services for UNIX should now be installed:

Windows -> All Programs

10) Open the Services for UNIX Administration shortcut, and click on User Name Mapping:

User Name Mapping on local computer

11) Click on “Show User Maps” and then click on the buttons for Listing Windows Users and Linux Users:

Creating a map

12) Choose “Administrator” (or the appropriate account you want to map the UNIX user to) in the Windows list, and your username in the Linux list. (In Ubuntu, UIDs for user accounts usually start from 1000)

13) Click “Add” to create a map. If you get the following warning, click “OK” to ignore it.

You have specified a special Windows account.

14) Click Apply at the top right corner.

15) Now, you’re ready to share folders! Just right click any folder you need to share, and share it from the NFS tab. You can click the Permissions button for more options, like allowing write access, which is disallowed by default.

NFS Sharing on Windows.

16) Next, mount the share on your UNIX/Linux machine. I used the following command on Ubuntu:

$ sudo mount <windows-server-ip-address>:/<windows_share_name> <path_to_local_mount_point>

For example:

$ sudo mount 192.168.1.3:/SharedFolder ~/windows_share

If this guide helped you, please let us know in the comments below!

Automatic Login For SSH/SFTP on Ubuntu

There are just three simple steps needed to automate your SSH/SFTP logins to remote Unix/Unix-like servers from your Ubuntu/Linux distribution, or an emulator on Windows like Cygwin.

1) Run ssh-keygen

abdullah@desktop:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/abdullah/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/abdullah/.ssh/id_rsa.
Your public key has been saved in /home/abdullah/.ssh/id_rsa.pub.
The key fingerprint is:
06:23:fc:34:0f:12:40:b2:5e:7c:41:eb:4f:a2:ab:24 abdullah@desktop
The key's randomart image is:

Randomart image

2) Run ssh-copy-id <username>@<server-name>

abdullah@desktop:~$ ssh-copy-id login@myserver.com
login@myserver.com's password: 
Now try logging into the machine, with "ssh 'login@myserver.com'", and check in:

 ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

3) Login to your server using ssh

abdullah@desktop:~$ ssh 'login@myserver.com'
Welcome to MyServer.com!
Last login: Sun Sep 25 23:22:21 2011 from 209.85.175.105
login@myserver.com:~# 

That’s all!

If you want a quick shortcut in the GUI, you could add a Custom Application Launcher to the panel with the ssh login command, as shown below:

Launcher Properties

Clicking the panel icon will directly open the terminal at the server with you logged in.

Note that this will also automate the login for SFTP, so you won’t need to type in your passwords there anymore too!

How to Delete a Directory in Linux

To delete or remove a directory in Linux, use the “-r” flag to the “rm” command. “r” stands for recursive.

rm -r <directory_name>

On some Linux systems, you might be prompted before each file is deleted. This means that the rm command has been aliased to “rm -i”, which turns on interactive mode. To run the original rm command and avoid the prompts, use “\rm”:

\rm -r <directory_name>

In the bash shell, just as the backslash is used to escape special characters, it is also used to escape aliases.

Caution!

Be careful to double check the directory name you provide, and be extra careful when using wildcards. There have been many stories of grief because of users ending up deleting important files and folders recursively.