Sometimes we need to suspend the machine when certain job is completed. Following is my gotosleep script to suspend my Ubuntu.

# ---- filename: gotosleep ----
#!/bin/bash
# This script will suspend this machine to sleep mode.
gnome-screensaver-command --lock
sleep 1 
dbus-send --system --print-reply --dest="org.freedesktop.Hal" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0
# ------------------------------

#

Ubuntu 11.04 requires HAL to provide abstract view on hardware. Thus,

sudo apt-get install hal