Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [me@mbeast ~]$ cat ~/.xinitrc
- xhost +localhost
- /home/me/.x0vnc-run &
- [me@mbeast ~]$ cat ~/.x0vnc-run
- #!/bin/sh
- while true
- do
- # Get active screens
- XSCREENS=$(xrandr | grep " connected" | perl -ne 'while (s/^\S+ connected[\s\D]* (\S+) .*$/$1/g) { print "$_"}')
- # Process input by newlines
- IFS=$'\n'
- # Start with VNC port 5900
- vncport=5900
- # Loop over each screen and start a separate VNC server
- LASTPID=0
- for geometry in $XSCREENS
- do
- # Get a notification, so -n later makes sense
- jobs &>/dev/null
- x0vncserver -PasswordFile /home/me/.vnc/passwd -display=:0 -rfbport=$vncport -Geometry=$geometry &
- # Get job changes
- new_job_started="$(jobs -n)"
- # If we got something, we know the previous command is infact running, so grab its PID
- if [ -n "$new_job_started" ];then
- LASTPID=$!
- else
- LASTPID=
- fi
- # Increase port count, for next VNC instance
- vncport=$((vncport+1))
- done
- # After creating all VNC sessions, now wait for the last one to exit (likely due to resolution changes)
- while s=`ps -p $LASTPID -o s=` && [[ "$s" && "$s" != 'Z' ]]; do
- sleep 1
- done
- # Pause slightly before respawning the VNC server, giving the Xorg a little time to set up
- sleep 5
- done
Advertisement
Add Comment
Please, Sign In to add comment