Friday, July 17, 2015

Remote Desktop Connection Manager

Remote Desktop Connection Manager is a very nice and freely available tool from Microsoft to manage multiple remote desktop sessions. Currently available version is 2.2 and it can be downloaded from here.

I liked following features in it :- 
  • Ability to group your servers and pass on configuration (password, display settings etc) from parent (group) to individual nodes (servers)
  • Ability to see the thumbnails (and also re-size them) for servers
  • Connect/Disconnect multiple server in one shot
Note :- I got error 3334 on trying to connect more than 5 servers simultaneously. Once I got this error then I was consistently getting it, even if concurrent connections were less than 5. Solution is to configure "Distributed Transaction Coordinator" (DTC, can be found under Component Services, shortcut to go to component services is to run dcomcnfg.exe) not to use any authentication. Detailed solution can be found here.


Wednesday, January 21, 2015

Setting Environment Variables in Ubuntu

For setting an environment variable for a particular user do it in one of the following files :-
  • ~/.pam_environment
  • ~/.profile
For setting a system wide environment variable do it in one of the following files :-
  • /etc/environment
  • /etc/profile.d/*.sh
I use ~/.profile for user specific variables and /etc/environment for system wide variables. The detailed explanation for this article can be found on Ubuntu Site.


Friday, January 2, 2015

Compiling a C program on Linux

Assuming you want to compile a file "test.c" and you want the name of the binary to be "hello"
> gcc -Wall -Wstrict-prototypes -ansi -pedantic test.c -o hello

Linux - SSH login without password

  1. Assuming you want to setup password less ssh login for user "user-1" from host "machine-1" to user "root" on host "machine-2"
  2. Login into "machine-1" as "user-1"
  3. Check if there exists a file "/home/user-1/.ssh/id_rsa.pub" (Note dot . before ssh). If this file exists then go to step 5
  4. Run this command with all default values 
    • ssh-keygen -t rsa
  5. Run this command to copy "/home/user-1/.ssh/id_rsa.pub" file to remote host 
    • ssh-copy-id -i root@machine-2
  6. Try login into remote machine and verify that it does not ask for any password
    • ssh root@machine-2
  7. You can also directly run commands on remote machine
    • ssh root@machine-2 hostname
References :-
  1. http://www.linuxproblem.org/art_9.html
  2. http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/

Wednesday, December 3, 2014

Run main method of a java class using maven

Exec Maven Plugin can be used.

Add following snippet to pom.xml

<project>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.3.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>hello.Application</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>

From command line call
>mvn exec:java


Bash script to compute time difference between two systems

#!/bin/sh

## Script to compute and log time difference between a remote host and a local host
## Please note that password less authentication is already set for the remote host

FILE=/home/dev/time.log
SLEEP=300 #seconds
rm -f $FILE
while [ true ]
do
    #Use `command` to store output of a command in a variable
    SERVER_TIME=`ssh root@10.112.81.41 date +"%s"`

    # $(command) syntax can also be used to store output of a command into a variable
    CLIENT_TIME=$(date +"%s")

    # Get diff of two variables. Note double ((
    DIFF=$(($SERVER_TIME-$CLIENT_TIME))

    # Echo to file and also concatnate command to text
    echo "Difference = [$DIFF] seconds at $(date)" >> $FILE

    sleep $SLEEP
done


Monday, December 1, 2014

Git - Discard local commits

>git reset --hard origin/master
Instead of origin/master we can go to a particular commit also
>git pull
Already up-to-date.