Home page Ubuntu C++ Hardware HTML i javascript Java Software SQL

Awk|bash – TightVNC, locked remote desktop session.

Added: 2012-06-23

TightVNC is good tool to remote control of computers. This tool is free, and may be used in commercial projects, if you place it in a program, you must pay for the license.

Sometime there are situations, that connection is lost with the remote desktop, and this interrupt is not result of problem with internet connection but with error with tightvncserver.

If you can connect to device by ssh client, you can try to create new session remote desktop, but in the event of a problem with the earlier session, newly created sessions typically will be interrupted when logged on to the device, or a connection will not be possible. First what you can do, is kill session by using command: tightvncserver -kill :[number display].

If this command do not work, then you must delete two files: /tmp/.X[numberDisplay]-lock and /tmp/.X11-unix/X[number Display]. If you want delete first session delete file: /tmp/.X1-lock and /tmp/.X-unix/X1 If these attempts fail, you can still reset the server.

The following script removes the session specified by the user

#!/bin/bash

echo "The script removes locked files of remote display."
read -p "Type the number of the remote display: " number;

if [ "$number" =  "" ]; then
	echo "The number is not specified!!!";
	exit 112;
fi

cd /tmp
ls -la | awk -vd=$number 'BEGIN{
}{
	if ((index($9, ".") != 0) && ((index($9, "lock") != 0))){
		if ($9 == ".X"d"-lock"){
			print "Deleting...";
			system("rm /tmp/.X"d"-lock");
			system("rm /tmp/.X11-unix/X"d);
		}
	}
}
'

exit 0;