#!/bin/sh type="MIT-MAGIC-COOKIE" if [ $# -ne 1 ]; then echo "usage: $0 " exit 1 fi display=$1 odisplay=$1 ok=0 xargs="" attempts="" checkCookie() { cookie=`xauth $xargs list $display 2> /dev/null | grep $type | \ sed 's/.*[ \t]\([^ \t][^ \t]*\)$/\1/' ` attempts="$attempts $display" } checkCookie if [ "$cookie" = "" ]; then # try removing trailing .# display=`echo $display | sed 's/\.[0-9]$//'` checkCookie fi if [ "$cookie" = "" ]; then # try :# if hostname is localhost or `hostname` dhost=`echo $display | sed 's/:[^:]*//'` [ "$dhost" = "localhost" -o "$dhost" = `hostname` ] && \ display=`echo $display | sed 's/^[^:]*//'` checkCookie fi if [ "$cookie" = "" ]; then #if XAUTHORITY is set, maybe we can find a cookie in the default location xargs="-f $HOME/.Xauthority" checkCookie fi if [ "$cookie" = "" ]; then echo "$0: could not find cookie for display $odisplay" echo " looked for entries under: $attempts" exit 1 fi echo $cookie exit 0