The desktop environment will have settings that control things like standby and hibernate power modes. This is usually good enough for simply saving electricity and putting the HD to sleep.
However, to answer the question you asked, a script could easily do a simple-minded check. To daemonize this script is slightly more involved but here is an example in Ruby to get you started:
last_user = Time.now
last_user = Time.now if `who | wc -l`.to_i > 0
system 'sudo shutdown -P +2' if Time.now - last_user >= 60 * 60
It won't always detect brief logins less than 10 seconds as written...
It's a little bit clunkier in bash, especially without using
if, but the equivalent is something like this:
while :; do
if [ `who | wc -l` -gt 0 ]; then
if [ $((`date +%s` - $last_user)) -ge 3600 ]; then
sudo shutdown -P +2