Tuesday 26 March 2013

Directory-based selection in ANT

To match a pattern of path to resources, use *:

*   matches only the first sub-directory and its content, plus the files of the current dir, no other directories
**  matches all sub-directoryes and their content
   for example, c:\path\to\something\**    will match everything under \something

to include the current dir for file search, start pattern path with **


Matching is done per-directory. This means that first the first directory in the pattern is matched against the first directory in the path to match. Then the second directory is matched, and so on. For example, when we have the pattern /?abc/*/*.java and the path /xabc/foobar/test.java, the first ?abc is matched with xabc, then * is matched with foobar, and finally *.java is matched with test.java. They all match, so the path matches the pattern.
To make things a bit more flexible, we add one extra feature, which makes it possible to match multiple directory levels. This can be used to match a complete directory tree, or a file anywhere in the directory tree. To do this, ** must be used as the name of a directory. When ** is used as the name of a directory in the pattern, it matches zero or more directories. For example: /test/** matches all files/directories under /test/, such as /test/x.java, or /test/foo/bar/xyz.html, but not /xyz.xml.
There is one "shorthand": if a pattern ends with / or \, then ** is appended. For example, mypackage/test/ is interpreted as if it were mypackage/test/**.
Example patterns:
**/CVS/* Matches all files in CVS directories that can be located anywhere in the directory tree.
Matches:
      CVS/Repository
      org/apache/CVS/Entries
      org/apache/jakarta/tools/ant/CVS/Entries
      
But not:
      org/apache/CVS/foo/bar/Entries (foo/bar/
      part does not match)
      
org/apache/jakarta/** Matches all files in the org/apache/jakarta directory tree.
Matches:
      org/apache/jakarta/tools/ant/docs/index.html
      org/apache/jakarta/test.xml
      
But not:
      org/apache/xyz.java
      
(jakarta/ part is missing).
org/apache/**/CVS/* Matches all files in CVS directories that are located anywhere in the directory tree under org/apache.
Matches:
      org/apache/CVS/Entries
      org/apache/jakarta/tools/ant/CVS/Entries
      
But not:
      org/apache/CVS/foo/bar/Entries
      
(foo/bar/ part does not match)
**/test/** Matches all files that have a test element in their path, including test as a filename.

Run command prompt on remote Win machine

Install Sysinternals Process Utilities from:

http://technet.microsoft.com/en-us/sysinternals/bb795533

 PsExec  Execute processes remotely.

The following command launches an interactive command prompt on \\marklap:
psexec \\marklap cmd
This command executes IpConfig on the remote system with the /all switch, and displays the resulting output locally:
psexec \\marklap ipconfig /all
This command copies the program test.exe to the remote system and executes it interactively:
psexec \\marklap -c test.exe
Specify the full path to a program that is already installed on a remote system if its not on the system's path:
psexec \\marklap c:\bin\test.exe

 

Process Explorer Find out which process locks a resource (Find menu), what files, registry keys and other objects processes have open, which DLLs they have loaded

 

Wednesday 20 March 2013

Linux processes

To find a process

Use pgrep command. pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to screen. For example display firefox process id:
# pgrep firefox
Sample outputs:
3356
 
or
# pidof firefox
3356  
 
Following command will list the process called sshd which is owned by a user called root:
$ pgrep -u root sshd


# ps 3356
Sample outputs:
PID   TTY  STAT   TIME   COMMAND
3356  ?    ..     ..     /path/to/executable
 
pstree shows running processes as a tree.  If a user name is specified, all process trees rooted at processes owned by that user are shown.
$ pstree
 
ps -u user  will show all processes of the user "user"
 $ ps -u user

Thursday 14 March 2013

VNC server on Linux

Setup VNC server on a Linux machine


Login with the user for which you want to allow remote desktop and enable vncserver startup from System ->Administration->Server Settings->Service configuration
Add the following lines to /etc/sysconfig/vncservers
VNCSERVERS="1:#username#”
VNCSERVERARGS[1]="-geometry 1024x768 -depth 16"
where #username# is the name of the user for which you want to allow remote desktop.
Start and stop VNC server to create the VNC startup file /home/ciuser/.vnc/xstartup
vncserver :1
vncserver -kill :1
The of /home/#username#/.vnc/xstartup must be as follows
#!/bin/sh

vncconfig -iconic &

# Uncomment the following two lines for normal desktop:
 unset SESSION_MANAGER
 exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
Copy & Paste the lines above into /home/#username#/.vnc/xstartup where #username# is the name of the user for which you want to allow remote desktop.
 vncserver uses the ports 5901 for display :1, 5902 for display :2, and so on.

The sessions are available on ports 5901 for regular VNC viewers (equivalent to VNC display 1) and on port 5801 for Web browsers. 
For example, in the browser you can access a machine with VNC server running:
http://machineName:5801 
which is equal to using a VNC desktop client, on this one you will use
machineName:5901

Wednesday 13 March 2013

IP classes A, B, C, D, E

IP addresse are of different classes:

Class A (1-127):
first octet always starts with 0 and is for the network address and next three octets - for the unique hosts inside the network.

Class B (128-191):
first octet always starts with 10. First and second octets are for the network address and next two octets - for the unique hosts inside the network.

Class C (192-223):
first octet always starts with 110. First three octets are for the network address and the last octet - for the unique hosts inside the network.



DHCP and DNS

DHCP - responds to requests from clients giving them unique IP address, subnet, gateaway, DNS server which are valide for a pecified period of time (TTL).
Having DHCP server to automatically configure machines in the network takes off the responsibilite of admins to configure each machine.

DNS - returns to client (like browser) the IP that corresponds to a given domain name.

Thursday 7 March 2013

Move/copy virtual machine around VMware environment

Goal is to move/copy a virtual machine to another datastore on another VMware server for virtualization, like ESXi.
In other words, create and register in the vSphere (VMware Workstation) a new VM from existing uploaded folder with such machine.

1. Physically move the directory of the virtual machine:
a) via Browse datastore to download it on the local machine and the via the Browse datastore on the other server upload it there
b) use VMware vCenter Converter http://www.vmware.com/products/converter/overview.html , this tool will relocate any machine around, just fill in appropriate IP of the source and destination servers

2. Once the virtual machine folder is uploaded, right-click the .vmx file -> Add to inventory.
This will add the machine to the list of machines in the left pane of the vSphere or VMware Workstation

You still may experience network conflicts of IP, MAC and so on after copying/moving a VM to new datastore, because it brings along the old network data (IP, MAC and so on). So you need to get new network data for the new machine.

FORCE VMWare To Generate a New MAC Address

  1. Shut down the Guest OS.
  2. Open up the .vmx file.
  3. Delete the following lines (that begin with…):
    ethernet0.addressType
    uuid.location =
    uuid.bios =
    ethernet0.generatedAddress =
    ethernet0.generatedAddressOffset =
  4. Boot up the Guest OS again, and it should generate new details in the vmx file (I’d check afterwards to be doubly sure).

The most common scenario for wanting to do this is if you’ve used a “template” Guest OS and copied it to multiple PCs, but accidentally clicked “I moved this Virtual Machine” rather than “I copied this Virtual Machine” when first booting the Guest OS in something like VMware Player.
If you tell VMware that the Guest OS was copied, it automatically generates new UUID info and MAC addresses. If you tell VMware that you moved the Guest OS, all unique identifiers are left alone (including the MAC address). By performing the steps above, you can get VMware to generate you some new, unique identifiers, and stop weirdness on your network ;)