#!/usr/bin/perl # Copyright 2013 by Joey Kelly, http://joeykelly.net # This script is licensed under the GPL. # # This is an extension to my original script (see below) # What we want to do is place this file in /etc/skel/bin/ or somesuch, so that each user can start VNC on his own port # without him having to guess or trial-an-error which port he should use. Based on his numerical ID (from /etc/password), # this script autogenerates a static port number that should not change. use strict; use warnings; my $home = `echo \$HOME`; chomp $home; #print "home = $home\n"; #my $stat = '-rw-rw-r-- 1 16777247 16777222 14 Dec 4 10:41 startvnc.sh'; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($home); my $uidlength = length $uid; my $portadd = substr $uid, $uidlength - 2, 2; my $port = 5900 + $portadd; print "UID = $uid, $uidlength digits, port = $port\n"; # The following is my original script: http://joeykelly.net/scratchpad/index.cgi?VNCSetupTips # so let's pillage at random^W^W^Wadapt it to work here. ##!/bin/bash ## Copyright 2004 by Joey Kelly, http://joeykelly.net ## This script is licensed under the GPL. ## ## This script is for the user to run to start a vnc session ## Hopefully this will eliminate the problem of getting calls whenever ## the process dies. ## ## here we set the port number we want to run on (vnc's real port = 5900 + $USERVNCPORT increment) #USERVNCPORT=10 # arbitrary number, must be unique for each user ## ## NOTE: ## if we want to kill the user's existing session, we would do: ## vncserver -kill :$USERVNCPORT ## ## we need to kill off the old pidfiles ## use rm -f so redhate doesn't complain with a prompt #rm -f /tmp/.X11-unix/X$USERVNCPORT #rm -f /tmp/.X$USERVNCPORT-lock ## ## now we start the vnc daemon #vncserver :$USERVNCPORT & #echo "VNC server restarted. Please log in to VNC as normal.\n" ## sometimes the terminal will hang... #sleep 3 #echo "Please press ." # so let's get down to business... # system "vncserver -kill :$portadd"; system "rm -f /tmp/.X11-unix/X$port"; system "rm -f /tmp/.X$port-lock"; system "vncserver :$portadd -geometry 1152x922 -depth 24 &"; print "\nMake sure to specify port :$portadd when running your VNC client.\n"; print "Please press to get your cursor back.\n";