Sleep Timer to Suspend in Ubuntu MATE 16.04 LTS [duplicate]

is there a way (best would be with GUI) to suspend my Computer after xx minutes? I am using Ubuntu MATE 16.04 LTS and tried everything, including Power management.

Thanks, philipp


If you don't mind using a terminal, you can do it this way.

Execute : sleep 2h 45m 20s && systemctl suspend -i

It suspends your system in 2 hours, 45 minutes, 20 seconds.

I wrote a script for getting a GUI like this:

enter image description here

enter image description here

Copy the content of the script below and save it in your home directory as fast_suspend.sh.

#!/bin/bash

#   Tested on : Ubuntu 16.04 LTS    
#   Date      : 19-May-2016
#                                                        
#   This program is distributed in the hope that it will be useful, 
#   but WITHOUT ANY WARRANTY; without even the implied warranty of  
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.            

set -- `zenity --title="Scheduled-action" \
    --forms \
    --text='<span foreground="green">Enter Relative time</span>'  \
    --add-entry="hours" \
    --add-entry="min" -\
    --add-entry="sec" \
    --separator=".0 " \
    --add-combo=action --combo-values="poweroff|restart|suspend|logout"`

hrs=$1
min=$2
sec=$3
action=$4

time=$hrs\h\ $min\m\ $sec\s

#Checking validity of the input :

re='^[0-9]*([.][0-9]+)?$'

if ! [[ $hrs =~ $re ]] || ! [[ $min =~ $re ]] || ! [[ $sec =~ $re ]]
then
    zenity  --error \
            --title="Invalid Input" \
            --text="You have entered an Invalid time! \n\nOnly positive integers supported"
            exit 1
fi



case $action in
    "poweroff")
        zenity --title=Confirm --question \
        --text="Your system is about to <span foreground=\"red\">$action</span> in ${hrs%%.*} hours ${min%%.*} minutes ${sec%%.*} seconds. \nAre you sure \?"
        if [ $? -eq 0 ]
        then 
            sleep $time && poweroff
        else
            exit
        fi  ;;

    "restart")
        zenity --title=Confirm --question \
        --text="Your system is about to <span foreground=\"red\">$action</span> in ${hrs%%.*} hours ${min%%.*} minutes ${sec%%.*} seconds. \nAre you sure \?"
        if [ $? -eq 0 ]
        then 
            sleep $time && reboot
        else
            exit
        fi  ;;
    "suspend")

        zenity --title=Confirm --question \
        --text="Your system is about to <span foreground=\"red\">$action</span> in ${hrs%%.*} hours ${min%%.*} minutes ${sec%%.*} seconds. \nAre you sure \?"
        if [ $? -eq 0 ]
        then 
            sleep $time && systemctl suspend -i
        else
            exit
        fi  ;;
    "logout")
        zenity --title=Confirm --question \
        --text="Your system is about to <span foreground=\"red\">$action</span> in ${hrs%%.*} hours ${min%%.*} minutes ${sec%%.*} seconds. \nAre you sure \?"
        if [ $? -eq 0 ]
        then 
            sleep $time && gnome-session-quit --logout --no-prompt
        else
            exit
        fi  ;;
esac

Additionally you can create a .desktop file to run it.

Copy the text below and save it as fast_suspend.desktop.

[Desktop Entry]
Type=Application
Terminal=false
Icon=
Name=fast_suspend
Exec=/home/your-user-name/fast_suspend.sh
Name[en_US]=fast_suspend

Provide execution permission for both files - execute :

chmod a+x ~/fast_suspend.sh ~/Desktop/fast_suspend.desktop

When you want to launch this window again, just double click on fast_suspend on the desktop.


If you're looking for a graphical tool, you may try qshutdown.