Announcement

Collapse
No announcement yet.

Hibernate at certain hours. It's possible?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Hibernate at certain hours. It's possible?

    Hello!

    I would like to know if it is possible to put the PC into hibernation for a certain period of time, for example, from 01:00 am to 12:00 pm and have it on the rest of the time.

    It's possible?​

    greetings and thanks.

    #2
    This might be helpful: https://www.baeldung.com/linux/auto-suspend-wake

    A quick search finds that hibernation isn't enabled in Ubuntu 'by default'. It can be enabled.
    Windows no longer obstructs my view.
    Using Kubuntu Linux since March 23, 2007.
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    Comment


      #3
      As Snowhog points out via link - suspend might allow this. Hibernation would be more difficult. I suspect that waking from Hibernation would require your hardware to support Wake-On-Lan in the BIOS. If that's try, then powering off would make more sense IMO. YOu would need some outside source to send the magic packet for this to work - like a router.

      There's good power state info here: https://wiki.archlinux.org/title/Pow..._and_hibernate
      Last edited by oshunluvr; Dec 07, 2023, 10:52 AM.

      Please Read Me

      Comment


        #4
        Hello, thanks for helping.

        Sorry to reply so late but I've been busy.

        I have tried the following command:​

        Code:
        sudo rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+%s')"
        And it worked, it went to sleep and at the specific time it turned on again.


        But I want this to be done automatically every day. On one of the websites, I saw that Cron can be used. Once inside the cron file I wrote the following:

        Code:
        30 16 * * * rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+%s')
        The problem is that nothing happens, it's as if Cron doesn't work. I have looked and cron is activated. But nothing happens.

        What am I doing wrong?

        Thanks and regards.​​

        Comment


          #5
          Which "cron file" did you use? If you used /etc/crontab did you specify a user? Did you use sudoedit or did you edit for a user?

          And possibly there are syntax/logical errors - see e.g. man 5 crontab:

          "[…] Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into new-
          line characters, and all data after the first % will be sent to the command as standard input.
          ​ […]"
          et al.

          And you would be missing an end quote - at least in your post above…

          PS:
          You could also start a simple shell script with cron which might be easier to debug…
          And additionally you could install the cron module for KDE Plasma's System Settings (sudo apt install kde-config-cron) which might be easier to use.
          Last edited by Schwarzer Kater; Dec 22, 2023, 09:10 AM. Reason: added PS, typos
          Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
          Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

          get rid of Snap script (20.04 +)reinstall Snap for release-upgrade script (20.04 +)
          install traditional Firefox script (22.04 +)​ • install traditional Thunderbird script (24.04)

          Comment


            #6
            I think I edit it as user.

            In cron program tasks I appear as a user and not as root.
            I have tried clicking execute task now, and it says permission denied. I guess that's where the error lies.

            But I don't know how to edit it as root.

            PS: to open and edit the file I simply write:

            crontab -e

            Comment


              #7
              If you need to execute something with elevated privileges or as a specific user, you could use the systemwide crontab in /etc/crontab :
              1. sudo systemctl stop cron.service
              2. Edit the systemwide crontab with sudoedit /etc/crontab
              3. sudo systemctl start cron.service
              But don't forget to remove the stuff you added to the user's crontab first.
              Last edited by Schwarzer Kater; Dec 22, 2023, 10:06 AM.
              Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
              Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

              get rid of Snap script (20.04 +)reinstall Snap for release-upgrade script (20.04 +)
              install traditional Firefox script (22.04 +)​ • install traditional Thunderbird script (24.04)

              Comment


                #8
                Hello again.

                I can't get it to work, I'm doing something wrong hehe.


                When I hit run now in the task scheduler, to see if it works it tells me: RTCWAKE: /dev/rtc0/unable to find device: permission deined.​

                EDIT:
                Maybe this command is not correct in cron?

                Couse if If I run it in the console it works.

                Code:
                30 16 * * * rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+%s')
                I just wanna the computer go to sleep (16:30 pm) and wake up (22:30 pm).

                You may only view thumbnails in this gallery. This gallery has 3 photos.
                Last edited by Anjunas; Dec 22, 2023, 12:49 PM.

                Comment


                  #9
                  IMO, the easiest way to do what you want, is to put the working command (what you did in the konsole) into a bash script, and have the CRON job call that script.
                  Windows no longer obstructs my view.
                  Using Kubuntu Linux since March 23, 2007.
                  "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                  Comment


                    #10
                    Originally posted by Anjunas View Post
                    Code:
                    30 16 * * * rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+%s')
                    As the black kitty mentioned, your above string is missing a parenthesis at the end, unless you mis-copied it. ......Which looks to be the case, based on the images

                    You also need to add a backslash ("") before the "%", as he also mentioned, as cron has some little quirks in text string formatting compared to bash.
                    The "permission denied.​" indicates sudo may need to be used, even though it is the system cron.

                    so:
                    30 16 * * * sudo rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+\%s')"

                    Some references

                    https://yunli.nl/blogs/2020-08-17_wa...e_and_crontab/
                    https://unix.stackexchange.com/quest...within-crontab

                    Comment


                      #11
                      Originally posted by claydoh View Post
                      30 16 * * * sudo rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+\%s')"
                      Given that sudo is being used here, won't that then result in a prompt for the password?
                      Windows no longer obstructs my view.
                      Using Kubuntu Linux since March 23, 2007.
                      "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                      Comment


                        #12
                        Originally posted by Snowhog View Post
                        Given that sudo is being used here, won't that then result in a prompt for the password?
                        Not for the 'root' cron.

                        Both my links, and others, seem to confirm that sudo is necessary here.

                        Comment


                          #13
                          So either sudo crontab -e (to use the 'root' crontab) and add

                          Originally posted by claydoh View Post
                          […]
                          30 16 * * * sudo rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+\%s')"
                          […]
                          or use the systemwide crontab like I mentioned in post # 7 and add
                          Code:
                          30 16 * * *    root    rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+\%s')"


                          But debugging is easier IMHO if you start a little shell script from either the 'root' crontab with sudo or execute it as root from the systemwide crontab - as Snowhog also wrote.
                          Also better use absolute paths in crontabs when you start a script.
                          Last edited by Schwarzer Kater; Dec 22, 2023, 04:12 PM. Reason: typos…
                          Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
                          Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

                          get rid of Snap script (20.04 +)reinstall Snap for release-upgrade script (20.04 +)
                          install traditional Firefox script (22.04 +)​ • install traditional Thunderbird script (24.04)

                          Comment


                            #14
                            Thank you very much everyone for the help.

                            I finally got it to work.

                            I added the root user​

                            I also liked the idea of ​​making a bash. Unfortunately my knowledge is very limited.

                            Would it be something like that?​​

                            Code:
                            sudo nano /home/users/me/myfuction.sh
                            Code:
                            #!/bin/bash
                            rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+\%s')"
                            Code:
                            sudoedit /etc/crontab
                            Code:
                            30 16 * * * /home/users/me/myfuction.sh​"
                            I don't have much idea but would it be like that?

                            Thank you and greetings.​
                            Attached Files

                            Comment


                              #15
                              Originally posted by Anjunas View Post
                              […]
                              I also liked the idea of ​​making a bash. Unfortunately my knowledge is very limited.

                              Would it be something like that?​​

                              Code:
                              sudo nano /home/users/me/myfuction.sh
                              Code:
                              #!/bin/bash
                              rtcwake -m mem -l -t "$(date -d 'today 22:30:00' '+\%s')"
                              You can use Kate to write scripts - it is much more comfortable (at least for me if I have a GUI…).
                              And the sudo before nano does not belong there (not necessary - in fact I consider it not correct in your case to create a script that belongs to root within your /home directory).


                              Within the Bash script you should not need the / anymore before the %s.



                              Originally posted by Anjunas View Post
                              Code:
                              sudoedit /etc/crontab
                              Code:
                              30 16 * * * /home/users/me/myfuction.sh​"
                              I don't have much idea but would it be like that?
                              […]
                              You forgot to specify the user root in field #6 - you want to execute the script with elevated privileges from the systemwide crontab if I understood correctly.
                              And there is a " too much at the end of the line.
                              Don't forget to make your script executable with chmod +x /home/users/me/myfuction.sh


                              Picture:
                              No sudo necessary if you use the systemwide crontab - you already specified to execute the command as root (in field #6)​


                              PS: Don't forget to stop and start cron.service before and after editing the systemwide crontab (!) - otherwise there is a little chance that unfortunate things could happen if you are unlucky…
                              Last edited by Schwarzer Kater; Dec 22, 2023, 05:06 PM. Reason: typos and additions
                              Debian KDE & LXQt • Kubuntu & Lubuntu • openSUSE KDE • Windows • macOS X
                              Desktop: Lenovo ThinkCentre M75s • Laptop: Apple MacBook Pro 13" • and others

                              get rid of Snap script (20.04 +)reinstall Snap for release-upgrade script (20.04 +)
                              install traditional Firefox script (22.04 +)​ • install traditional Thunderbird script (24.04)

                              Comment

                              Working...
                              X