Wednesday 31 March 2010

samba jcifs single server/host multiple computer or host names

I was using jcifs in a java application to access files on a remote file server.

Samba and hence jcifs do not like it when you use a path which contains an alias rather than the actual computer or host name.

So for example if the hostname of your remote file server is fileserver1, but for some reason you want to access some files on this server using JCIFS or samba but want to refer to it as fileserver2 and in your local hosts file you have fileserver2 pointing to the same IP address as fileserver1, then when you try to access \\fileserver2\.... you get the following error:

jcifs.smb.SmbException: Failed to connect to server
java.net.UnknownHostException: fileserver2
at jcifs.UniAddress.getAllByName(UniAddress.java:315)
at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:852)
at jcifs.smb.SmbFile.connect(SmbFile.java:939)
at jcifs.smb.SmbFile.connect0(SmbFile.java:868)
at jcifs.smb.SmbFile.queryPath(SmbFile.java:1321)

The solution is the following:
  1. open registry editor on the fileserver. 
  2. go to HKEY_Local_Machine \ System \ CurrentControlSet \ Services \ LanmanServer \ Parameters 
  3. create a new multi-string value parameter with the name of "OptionalNames". 
  4. edit the data of this newly created field and add as many aliases as you want. One alias on a new line. So in the above case, you would just add fileserver2. 
  5. Now on both the fileserver and your local client add fileserver2 to your hosts file (C:\WINDOWS\system32\drivers\etc\hosts) with the same IP address of fileserver1. 
  6. reboot the fileserver. 

I recently found that an easier way is just to create a new value under HKEY_Local_Machine \ System \ CurrentControlSet \ Services \ LanmanServer \ Parameters on the fileserver and then reboot the fileserver:

Value name: DisableStrictNameChecking
Data type: REG_DWORD
Radix: Decimal
Value: 1

Wednesday 17 March 2010

Rsync over ssh hanging / freezing in Cygwin problem

Sometimes when using rsync over ssh under cygwin in windows to synchronise files from one server to another, the rsync process copies a few files and then just hangs. Sometimes the rsync process utilises 100% cpu and sometimes 0% cpu, but in either case no more files are synchronised.

The solutions is to use rsync as a daemon on the remote server.

run the following in cygwin on the remote windows machine.

cygrunsrv --install "rsyncd" --path /usr/bin/rsync --args "--daemon --no-detach" --desc "Starts a rsync daemon for accepting incoming rsync connections" --disp "Rsync Daemon" --type auto

then create the following file /etc/rsyncd.conf

In this file you should have something like:

max connections = 10
log file = /var/log/rsync.log
timeout = 300
[pub]
comment = Random things available for download
path = /path/to/my/public/share
read only = no
list = yes
Note: in the above example the name of the module is pub.

Then start the service. You can use "net start rsyncd" to do this.

Now when you want to rsync use:

rsync ... src rsync://user@host/pub/datafolder

notice that you must use modules when using rsync daemon. In this case the module is pub.

The above rsync will copy the files to /path/to/my/public/share/datafolder

Friday 5 March 2010

Finding all hosts on a network subnet (Windows Cygwin Bash)

Just run the below in Cygwin bash command shell:

for ip in $(seq 1 254); do ping -w 20 -n 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && echo "192.168.1.$ip UP" || : ; done