#! /bin/bash connection_state=$1 delai_offline="5" delai_online="6" echo $connection_state switchwindowdecorator() { status=$1 if [ $status -eq 0 ] then echo '----------- VNC connection detected, killing compiz ------------' #killall compiz metacity --replace& else echo '----------- VNC connection finished, activating compiz ------------' sleep 2 #compiz #gtk-window-decorator --replace compiz& ##emerald --replace& fi } while [ '1' -eq '1' ] do if [ $connection_state -eq 0 ] then echo '----------- VNC offline listening ------------' if ((netstat -p -n | grep -E "192.168.10.22(%[1-9]*)*:5900.*ESTABLISHED")||(netstat -p | grep -E "78.234.236.166(%[1-9]*)*:5959.*ESTABLISHED")) then switchwindowdecorator 0 connection_state=1 #on passe en statut "connecté" sleep $delai_offline fi elif [ $connection_state -eq 1 ] then echo '----------- VNC online listening ------------' if ((netstat -p -n | grep -E "192.168.10.22(%[1-9]*)*:5900.*ESTABLISHED")||(netstat -p | grep -E "78.234.236.166(%[1-9]*)*:5959.*ESTABLISHED")) then sleep $delai_online else switchwindowdecorator 1 connection_state=0 #on passe en statut "déconnecté" fi else echo 'parametre incorrect ' fi done