Put ubuntu PC to standby after X minutes

I didn't test it, I could be missing a step.

  1. Use System Setting → Power / Brightness. Set all setting you need and as you want
  2. Create an override file from the current user settings and place it in /usr/share/glib-2.0/schemas/

    echo "[org.gnome.settings-daemon.plugins.power]" > 90_mypower.gschema.override
    gsettings list-recursively org.gnome.settings-daemon.plugins.power | awk '{ gsub("org.gnome.settings-daemon.plugins.power ","") ; print $1"="$2 }' >> 90_mypower.gschema.override
    
    sudo mv 90_mypower.gschema.override /usr/share/glib-2.0/schemas/
    sudo chown root:root /usr/share/glib-2.0/schemas/90_mypower.gschema.override
    sudo chmod +r /usr/share/glib-2.0/schemas/90_mypower.gschema.override
    
  3. Compile the schemas

    sudo glib-compile-schemas /usr/share/glib-2.0/schemas
    
  4. Create a lock file for all org.gnome.settings-daemon.plugins.power keys and place it in /etc/dconf/db/gdm.d/locks/

    gsettings list-keys org.gnome.settings-daemon.plugins.power | xargs -L 1 -I{} echo /org/gnome/settings-daemon/plugins/power/{} > 90-mypower-locks
    
    sudo cp 90-mypower-locks /etc/dconf/db/gdm.d/locks/90-mypower-locks
    sudo chown root:root /etc/dconf/db/gdm.d/locks/90-mypower-locks
    sudo chmod +r /etc/dconf/db/gdm.d/locks/90-mypower-locks
    
  5. Update for locks

    sudo dconf update
    

As you are looking for system administration, nice to learn:

  1. Watch dconf for change

    dconf watch /
    
  2. Change power setting from GUI, watch for messages

  3. Open dconf-editor, go through same path, select a key
  4. Look at bottom, it shows its schema name/id: org.gnome.settings-daemon.plugins.power

References:

  • dconf System Administrator Guide
  • Shouldn't dconf-editor and gsettings access the same database?
  • dconf Settings: defaults and locks
  • man gsetting, man dconf

On the bottom of this answer are instructions for installing sleepd if you really insist. However that package is pretty much outdated for modern hardware.

If you are going to write a program, you can consider the following sources:

  • Devices in /dev/input/
  • If a user is logged in, rely on the desktop session manager. Its properties for consideration are described at How does ubuntu determine inactivity before suspending?

Instead of using sleep(3) in the code (like sleepd does), it is more battery-friendly if you use poll(3) or select(3) which have a timeout parameter. (This assumes that the /dev/input/* devices are poll-able, I don't know if that is the case but you should look up the documentation)


Upstream (git repo) has already removed the default hal dependency (commit), so you can try building from sources. The following commands were tested in a Kubuntu 13.10 Live environment. It installs the build dependencies, fixes a bug in the Makefile that prevented HAL from getting disabled and finally creates a deb package.

sudo apt-get install build-essential git debhelper libapm-dev
git clone git://git.kitenet.net/sleepd.git
cd sleepd
sed 's/ifdef USE_HAL/ifeq ($(USE_HAL), 1)/' -i Makefile
dpkg-buildpackage -b -us -uc

This produces a sleepd_2.05_amd64.deb package in the parent directory which you can then install on machines. This package requires a battery or AC interface to be present (e.g. /sys/class/power_supply/*), otherwise it will try APM. Since modern machines do not use APM, but ACPI, it will exit silently.

So while the package builds and install fine, you are better off with writing a new daemon if something like this is not already implemented.