Pages

Sunday, August 25, 2013

add virtualbox guest to network domain

I have done this on a linux host and windows 7 guest.  The requirement was to put the windows 7 guest to office network.

1. create a bridged adapter for the guest, using virtualbox settings window.


2.  This will create an adapter on the guest that will have the IP picked from ntework domain in which your host exists. That means The IP will be looking similar to the host IP, that can be pinged from a different PC.

3. Now, go to your guest OS, Start-> My computer-> right click -> Properties

4. Click on 'change settings' that you see on the right bottom side. you will get below window.


5. Click on 'Change' button in the above window. (see 'To rename this computer or domain...'). you will get below window.


6. You will see 'Workgroup' enabled. Change it to 'Domain'(see under 'Member of'). Add your domain name here and click okay. This will make the OS to contact DNS server and register itself . Here on you will be able to login to domainname/username in your Guest OS.



enable telnet on non default port, allow root login

Telnet deamon listen to port 23 by default. If you want to enable make it listen on different port(for example 2233), perform following steps:



For BusyBox telnet:

=> start telnetd on server as "telnetd -p 2233". This will run the deamon in background making it listen on port 2233.
=> from client, login as 'telnet <server ip> 2233'
=> Note that busybox telnet does not allow root login.


For ineutil telnet:

=>You will have a config file 'telnet' in /etc/xinetd.d/ directory
=> The file looks like 


# default: on
# description: The telnet server serves telnet sessions; it uses \
# unencrypted username/password pairs for authentication.
service telnet
{
flags = REUSE IPv4
socket_type = stream
only_from = 0.0.0.0
wait = no
server = /usr/sbin/in.telnetd
instances = 5
log_on_failure += USERID
disable = no
}

=> to this file, add entry

port = 2323

to change listening port. Also edit /etc/services file and modify 

telnet          23/tcp

to 

telnet          2323/tcp

To allow root login, add entry

user = root
If you want to restrict only certain clients to be able to login, modify 

only_from = <ip range>








Wednesday, August 14, 2013

subtitle and video synchronization in vlc player

Sometimes, the subtitles we download from internet do not sync with the video we are playing. Either it will be little ahead or behind, resulting in a different subtitle appearing for a different picture frame.

By knowing how much is the lag between video and the subtitle, we can sync these two, to play it proper.

to know the lag, play the video, try to listen to most commonly recognizable word. Not down the time stamp at that moment. Now, you have to find out at what timestamp actually that word being played from the subtitle file. Either you open the file with a word processor and see around that time or while playing the video itself you will know what time the subtitle was/is being played.

For example, In my video, I hear a sound 'Hey Macho' that i can clearly recognize. I note that it is played at 4 min 11 sec. From the file, the subtitle 'Hey Macho' is being played at 4 min 5 sec. So the lag is around 6 seconds.

To overcome this lag, on your VLC player, go to Tools->Track synchronization


The track synchronization window looks like below:

the Subtitle track synchronization window shows 1.7 seconds value which means the subtitle will be played 1.7 second late compared to how it would have played without this synchronization.





Tuesday, July 16, 2013

count number of blank lines in a file using grep



To count number of blank lines in a file, we use following grep expression.

$grep -c '^$' filename

=> this will try to extract lines starting and ending with nothing in between.

Saturday, July 13, 2013

how to debug bash shell script

 Unlike C/C++ applications, wherein you will you have to printf messages to debug, there is an easier and more detailed way of debugging shell scripts, specially in bash.

In your shell script, you can add

set -x

at the top of the script, this will make bash to print each command line it parse in your shell script, plus the result of the command as well.

Doing this permanently enable tracing, until you remove it or put "set +x" which is the default.

If you just want to see how it goes once, you can run your script "myscript.sh", try

$ bash -x myscript.sh

output looks like

+ var1=hi
+ var2='how are you'
++ paste hi how are you
paste: hi: No such file or directory
+ var3=
+ echo

"+" means, the sublevel of the command from the main shell script. i.e one + indicates the exact line of command as written in shell script, 2 +s indicate another command within the line of code you have written inside the script.

There is another, lesser debug info method.

$ bash -v myscript.sh

output looks like

#!/bin/bash
var1="hi"
var2="how are you"
var3=`paste $var1 $var2`
paste $var1 $var2
paste: hi: No such file or directory
echo $var3

This will just echo each line of the script as it parses, plus errors or echos from script if any.

Upgrade Java Runtime (JRE) on Debin/Ubuntu

Its high time you upgrade your JRE on your linux, as any version before Java 7 update 11 has serious security flaws. 

Firefox, by default blocks java based on the version you have installed. It means it doesn't allow you to run any java application using these security-issue-ridden java versions.

But, not the same with other browsers or your OS. You got to update it immediately.

NOTE: openjdk jre is also similar to oracle java, hence you can expect same issues with open jdk too. Until you get an update on openjdk, I suggest you use oracle java, well it is not too complex to install oracle java as it looks like on the surface.

Here is how to be done: (OS: Ubuntu)


  1. Download latest java from oracle site http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html
  2. if you are using 32 bit linux(most likely intel, x86 arch), choose the right file to download(rpm type for redhat based, .gz for debian based)
  3. untar using command 'sudo tar -xzvf jre-7u25-linux-x64.tar.gz -C /usr/java/
  4. To enable this java on Firefox, create soft link for a lib libnpjp2.so from your java directory to firefox plugin directory. It looks something like this:                                                                 "sudo ln -s /usr/java/jre1.7.0_25/lib/amd64/libnpjp2.so /usr/lib/firefox/plugins/"
  5. to verfiy, restart firefox, go to "about:plugins" in address bar,  see if you have following information: "

    Java Plug-in 1.7.0_25

    File: libnpjp2.so
    Path: /usr/java/jre1.7.0_25/lib/amd64/libnpjp2.so "

    that's it, you are upgraded!

    For google-chrome, you don't have to do anything if you have untarred the jre under /usr/java. To verify, restart your chrome, go to 

    chrome://plugins/

    Look for 

    Java(TM) Download Critical Security Update
    Java plug-in for NPAPI-based browsers.
    Name:Java Plug-in 1.7.0_25
    Description:Java plug-in for NPAPI-based browsers.
    Version:
    Location:/usr/java/jre1.7.0_25/lib/amd64/libnpjp2.so

    (don't forget to remove older versions of java)

Saturday, July 6, 2013

convert images to pdf


to convert one or multiple images to pdf file, use the command

$convert scan_*.jpg scanned_docs.pdf

convert command comes with package imagemagick