Thanks for the help folks. I finally got it to work and below is the working script.
Thanks again.
#!/bin/sh
CDROM=`grep cdrom /etc/mtab`
if [ -z "$CDROM" ]; then
echo Mounting Cdrom under /cdrom
mount -r -t iso9660 /dev/cdrom /cdrom
else
echo Unmounting Cdrom mounted under /cdrom
umount /cdrom
sleep 1
eject
fi