Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 42

Thread: [SOLVED] Automatically Resume from Sleep/Standby/Suspend

  1. #31
    Join Date
    Oct 2008
    Location
    Down Under
    Beans
    1,566
    Distro
    Xubuntu 12.10 Quantal Quetzal

    Re: Automatically Resume from Sleep/Standby/Suspend

    Quote Originally Posted by RedgeOnline View Post
    Absolute times don't seem to work for me: might be timezone related. Anyway: I created a script that uses relative timing. Called like: suspend_for 1 hour 30 minutes

    Code:
    #!/bin/sh
    
    # Auto suspend and wake-up script
    
    # Puts the computer on standby and automatically wakes it up after specified period
    
    # How to use: download this script and place it on you computer.
    # Call the script like this:
    # suspend_for 1
    # suspend_for 1 hour
    # suspend_for 2 hours
    # suspend_for 1 minute
    # suspend_for 60 minutes
    # suspend_for 1 hour 30 minutes
    # suspend_for 2 hours 1 minute
    
    # Original version courtesy of http://ubuntuforums.org/member.php?u=130449
    # from thread http://ubuntuforums.org/showthread.php?t=938533&page=2
    # Edited by Romke van der Meulen <redge.online@gmail.com>
    
    # ------------------------------------------------------
    # Argument check
    MINARGS=1
    MAXARGS=4
    E_BADARGS=65
    
    if [ $# -lt "$MINARGS" ] || [ $# -gt "$MAXARGS" ]; then
      echo "Usage: `basename $0` [[number] hours/h] [[number] minutes/m]"
      echo "E.G.: `basename $0` 2 hours"
      echo "E.G.: `basename $0` 30 minutes"
      echo "E.G.: `basename $0` 2 hours 30 minutes"
      echo "E.G.: `basename $0` 2 h 30 m"
      exit $E_BADARGS
    fi
    # ------------------------------------------------------
    
    # Get root
    sudo /bin/true
    
    # Determine sleep interval
    hours=0
    minutes=0
    multiply=0
    total=0
    
    # Check for first argument set, default hours
    multiply=3600
    if [ $# -gt 1 ]; then
    	if [ "$2" = "minutes" ] || [ "$2" = "minute" ] || [ "$2" = "m" ]; then
    		multiply=60
    		minutes=$1
    	else
    		multiply=3600	
    		hours=$1
    	fi
    fi
    
    # Add time from first argument set
    total=`expr $1 \* $multiply`
    
    # Check for second argument set, default minutes
    multiply=0
    if [ $# -gt 2 ]; then	
    	if [ "$4" = "hours" ] || [ "$4" = "hour" ] || [ "$4" = "h" ]; then
    		multiply=3600
    		hours=`expr $3 + $hours`
    	else
    		multiply=60	
    		minutes=`expr $3 + $minutes`
    	fi
    	
    	# Add time from second argument set
    	total=`echo "$total + ($3 * $multiply)" | bc`
    fi
    
    # Let user know what we're going to do
    echo "Going to suspend for $hours hours $minutes minutes ($total seconds)"
    echo "To cancel, press Ctrl+c within the next 5 seconds."
    sleep 5
    
    # Set wake up time,
    sudo rtcwake -u -s $total -m on &
    
    # give rtcwake some time to make its stuff
    sleep 2
    
    # then suspend
    sudo pm-suspend
    
    # Wake up with monitor disabled
    xset dpms force off
    
    # and console cleared
    clear
    
    # Any commands you want to launch after resume
    # can be placed here
    # Remember: sudo may have expired by now
    echo "Good morning!"
    \EDIT: I updated the script so that it can handle both hours and minutes.
    \EDIT: Put down the latest version of the script while I'm here again
    Thank You, this is great ! works well.

  2. #32
    Join Date
    Oct 2008
    Location
    Down Under
    Beans
    1,566
    Distro
    Xubuntu 12.10 Quantal Quetzal

    Re: Automatically Resume from Sleep/Standby/Suspend

    I try this in Mint 8 64bit and I always get incorrect times like these copied examples -

    $ ~/suspend_for 7 hour 39 minute

    Going to suspend for 7 hours 74 minutes (27540 seconds)
    $ ~/suspend_for 1 minute

    Going to suspend for 7 hours 1 minutes (60 seconds)
    $ ~/suspend_for 7 hour
    Going to suspend for 7 hours 35 minutes (25200 seconds)

    What is going wrong ?

  3. #33
    Join Date
    Jan 2008
    Location
    Groningen, Netherlands
    Beans
    13
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Automatically Resume from Sleep/Standby/Suspend

    Quote Originally Posted by Rodney9 View Post
    I try this in Mint 8 64bit and I always get incorrect times like these copied examples -


    What is going wrong ?
    Did you copy the entire script correctly?

  4. #34
    Join Date
    Oct 2008
    Location
    Down Under
    Beans
    1,566
    Distro
    Xubuntu 12.10 Quantal Quetzal

    Re: Automatically Resume from Sleep/Standby/Suspend

    Quote Originally Posted by RedgeOnline View Post
    Did you copy the entire script correctly?
    I'm sorry I should have responded before now , you are correct , I did not copy it correctly.

    It is now working perfectly.

  5. #35
    Join Date
    Dec 2010
    Location
    Estonia
    Beans
    101
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Automatically Resume from Sleep/Standby/Suspend

    Nice script! Though it would be nice if someone knew how to upgrade the script so the wakeup time could be entered also as time, eg. 'suspend_until 14:45'.
    (no dates, just plain 24-h computer clock (not UTC))

    PS i'd recommend changing line
    Code:
    if [ "$2" = "minutes" ] || [ "$2" = "minute" ] || [ "$2" = "m" ]; then
    to
    Code:
    if [ "$2" = "minutes" ] || [ "$2" = "minute" ] || [ "$2" = "m" ] || [ "$2" = "min" ]; then
    otherwise 'min' value might get defined as hour.

    PS2 Why is the rtcwake kept loaded in memory after wakeup so it has to be killed every time?
    Last edited by layr; May 29th, 2011 at 03:05 PM.

  6. #36
    Join Date
    Jan 2008
    Location
    Groningen, Netherlands
    Beans
    13
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Automatically Resume from Sleep/Standby/Suspend

    Quote Originally Posted by layr View Post
    Nice script! Though it would be nice if someone knew how to upgrade the script so the wakeup time could be entered also as time, eg. 'suspend_until 14:45'.
    (no dates, just plain 24-h computer clock (not UTC))
    Your wish is my command. Does this work?

    Code:
    #!/bin/bash
    
    # Auto suspend and wake-up script
    #
    # Puts the computer on standby and automatically wakes it up at specified time
    #
    # Written by Romke van der Meulen <redge.online@gmail.com>
    #
    # Takes a 24hour time HH:MM as its argument
    # Example:
    # suspend_untill 9:30
    # suspend_untill 18:45
    
    # ------------------------------------------------------
    # Argument check
    if [ $# -lt 1 ]; then
    	echo "Usage: suspend_untill HH:MM"
    fi
    
    # Check whether specified time today or tomorrow
    DESIRED=$((`date +%s -d "$1"`))
    NOW=$((`date +%s`))
    if [ $DESIRED -lt $NOW ]; then
    	DESIRED=$((`date +%s -d "$1"` + 24*60*60))
    fi
    
    # Kill rtcwake if already running
    sudo killall rtcwake
    
    # Set RTC wakeup time
    sudo rtcwake -l -m on -t $DESIRED &
    
    # feedback
    echo "Suspending..."
    
    # give rtcwake some time to make its stuff
    sleep 2
    
    # then suspend
    sudo pm-suspend
    
    # Any commands you want to launch after wakeup can be placed here
    # Remember: sudo may have expired by now
    
    # Wake up with monitor disabled
    xset dpms force off
    
    # and a fresh console
    clear
    echo "Good morning!"
    Quote Originally Posted by layr View Post
    PS2 Why is the rtcwake kept loaded in memory after wakeup so it has to be killed every time?
    I have no idea. Annoying, isn't it?

  7. #37
    Join Date
    Dec 2010
    Location
    Estonia
    Beans
    101
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SOLVED] Automatically Resume from Sleep/Standby/Suspend

    Thanks a lot RedgeOnline! Works like a charm (Y)
    PS i hope you won't mind if i share this script in Estonian linux forum. Many could use this awesome script
    Last edited by layr; May 30th, 2011 at 11:35 AM.

  8. #38
    Join Date
    Jan 2008
    Location
    Groningen, Netherlands
    Beans
    13
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SOLVED] Automatically Resume from Sleep/Standby/Suspend

    Quote Originally Posted by layr View Post
    Thanks a lot RedgeOnline! Works like a charm (Y)
    PS i hope you won't mind if i share this script in Estonian linux forum. Many could use this awesome script
    Go right ahead.

  9. #39
    Join Date
    Dec 2010
    Location
    Estonia
    Beans
    101
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [SOLVED] Automatically Resume from Sleep/Standby/Suspend

    Added the 'going to suspend for X' line again + few alsa-mixer lines, to make sure volume is up and unmuted (learned the hard way )
    PS your system might have different alsamixer configuration (for instance the '0' in the amixer line is my sound card, your's might be different).


    Code:
    #!/bin/bash
    
    # Auto suspend and wake-up script
    #
    # Puts the computer on standby and automatically wakes it up at specified time
    #
    # Written by Romke van der Meulen <redge.online@gmail.com>
    #
    # Takes a 24hour time HH:MM as its argument
    # Example:
    # suspend_until 9:30
    # suspend_until 18:45
    # suspend_until 0325
    # suspend_until 515
    
    # (just drag the scriptfile into terminal window and add time to the line)
    
    # ------------------------------------------------------
    # Argument check
    if [ $# -lt 1 ]; then
    	echo "Usage: suspend_until HH:MM"
    fi
    
    # Check whether specified time today or tomorrow
    DESIRED=$((`date +%s -d "$1"`))
    NOW=$((`date +%s`))
    if [ $DESIRED -lt $NOW ]; then
    	DESIRED=$((`date +%s -d "$1"` + 24*60*60))
    fi
    
    
    # Define hours/mins/sec to wake-up (for printing purposes only):
    hours=$(((DESIRED-NOW)/3600))
    minutes=$((  ((DESIRED-NOW)-(hours*3600))/60  ))
    seconds=$(( ((DESIRED-NOW)-((hours*3600)+(minutes*60)))  ))
    
    # Kill rtcwake if already running
    sudo killall rtcwake
    
    # Let user know what we're going to do
    echo "Going to suspend for $hours h $minutes min"
    
    echo "To cancel, press Ctrl+c within the next 10 seconds."
    sleep 10
    
    # Set RTC wakeup time
    sudo rtcwake -l -m on -t $DESIRED &
    
    # feedback
    echo "Suspending..."
    
    # give rtcwake some time to make its stuff
    sleep 2
    
    # then suspend
    sudo pm-suspend
    # -------------------------------------------------------------------------------------
    # Any commands you want to launch after wakeup can be placed here
    # Remember: sudo may have expired by now
    
    # Wake up with monitor disabled
    # xset dpms force off
    
    # Set volume level and (just in case) unmute system
    amixer -c 0 set Master 80% unmute
    amixer -c 0 set PCM 70% unmute
    
    # echo "Good morning"
    
    # Open VLC (vlc + path to your audio/video file)
    vlc '/home/USER/Music/audiofile.mp3'
    
    # Unload rtcwake if it's running, otherwise next time computer won't wake up from sleep
    SERVICE='rtcwake'
    if ps ax | grep -v grep | grep $SERVICE > /dev/null
    then
        echo "$SERVICE running, killing process..."
        sudo killall rtcwake
    else
        echo "$SERVICE is not running, no action taken."
    fi
    Makes a damn good alarm-clock

  10. #40
    Rebelli0us is offline Extra Foam Sugar Free Ubuntu
    Join Date
    Feb 2008
    Beans
    722

    Re: [SOLVED] Automatically Resume from Sleep/Standby/Suspend

    Linux has the equivalent of Windows' "Task Scheduler" (I forget what they call it), which may also have the ability to "wake up computer to run a task". In windows it runs the named task at the time set and then goes back to S3 suspend. If you figure out how it works in Linux I'd like to know as well.

Page 4 of 5 FirstFirst ... 2345 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •