command line work script doesn't

Hello,

I'm stuck and confused as to why when I execute things form the command line it works but when in a script it doesn't.

My script:

### creating a lock on the console
touch /var/run/console.lock
chmod 600 /var/run/console.lock
echo "$User" >> /var/run/console.lock
touch /var/run/console/larry
chmod 600 /var/run/console/larry
echo "1" >>/var/run/console/larry
rm -f /tmp/.X0-lock

  \#\#\# stopping the gnome-login manager
  for pid in \`ps -ae|grep gdm|awk '\{print $1\}'|sort -r\`
  do
      kill -9 $pid
  done
  rm -f /tmp/.X0-lock

  \#\#\# getting the Gnome Desktop Manager      
  kill -9 \`ps -aef|grep gdm|grep X|awk '\{print $2\}'\`
  
  su - larry  -c 'exec /bin/sh' <<EOF

   xauth list|grep \`hostname\` >/dev/null
   if [ $? -ne 0 ]
   then
      xauth generate :0 .
   fi

  \#\#\#\# start the default desktop
  /usr/bin/X11/startx& >/dev/null 2>&1 

EOF

It does not work but if I rlogin form another machine and run the scipt on the command line (execute each line at the prompt) it works. This is REDHAT 7.2

Thanks

Do you get any specific errors? Does any part of the script appear to actually execute?

oombra,

Every thing seems to execute with the except when I execut the startx command. As root on the command line things work fine but as root executing the script it doesn't work. I get is:

Fatal server error:
Server is already active for display 0
If this server is no longer running, remove /tmp/.X0-lock and start again.