function startVM ( ) { ( flock --nonblock 9 || exit 1 nohup kvm ${OPTIONS[@]} >/dev/null 2>&1 ) 9>"/var/lock/kvm-${IMG}.lock & # $IMG enthält den Namen der VM" } # $OPTIONS ist ein Array mit qemu/kvm Aufrufoptionen OPTIONS=("${OPTIONS[@]}" "-vnc unix:${VNC_SOCKET}" "-usbdevice tablet") startVM number_of_attempts="0" max_attempts="10" socket_missing="1" while [ "$socket_missing" -ne 0 -a "$number_of_attempts" -lt "$max_attempts" ] do socat -T 0.1 - "UNIX-CONNECT:${VNC_SOCKET}" >/dev/null 2>&1 socket_missing="$?" if [ "$socket_missing" -ne 0 ] then sleep 0.1 fi number_of_attempts="$(($number_of_attempts + 1))" done if [ "$socket_missing" -eq 0 ]; then socat – "UNIX-CONNECT:${VNC_SOCKET}" exit $? else exit 1 fi