I had a problem today where trying to load things into an Xvfb was not working because the xvfb was not yet initialized. The problem script is as follows:
#Start the Xvfb on DISPLAY :1,
`dirname $0`/Xvfb :1 -screen 0 1280x1024x24 -ac -br -fbdir /dev/shm & xvfbpid=$!
DISPLAY=:1 xli -onroot -fillscreen `dirname $0`/images/background.png
The only solution I see on the web is to insert a sleep statement. I don't much like that. The solution I came up with is to wait for the display to be ready to use via xdpyinfo. The working script:
#Start the Xvfb on DISPLAY :1,
`dirname $0`/Xvfb :1 -screen 0 1280x1024x24 -ac -br -fbdir /dev/shm & xvfbpid=$!
#Wait for Xvfb to initialize
ACTIVE=9999
while [ $ACTIVE -ne 0 ] ; do
xdpyinfo -display :1 &> /dev/null
ACTIVE=$?
done
DISPLAY=:1 xli -onroot -fillscreen `dirname $0`/images/background.png