Questions about rtcwake

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
abel

Questions about rtcwake

Post by abel »

I was looking for a way to wake up my computer automatically at a fixed time every day, and I found this script (I called it test.py and made it executable):
--------------------
#!/usr/bin/env python3
import datetime
import subprocess
###############################################
# set wakeuptime and the command
hour = 20
minutes = 0
command = "echo Hello"
###############################################
currtime = str(datetime.datetime.now().time()).split(":")[:2]
minutes_set = hour*60 + minutes
minutes_curr = int(currtime[0])*60 + int(currtime[1])
if minutes_curr < minutes_set:
minutes_togo = minutes_set - minutes_curr
else:
minutes_togo = minutes_set + 1440 - minutes_curr
interval = minutes_togo*60

run = "rtcwake -m no -s "+str(interval)+" && "+"sleep 60 &&"+command
subprocess.call(['/bin/bash', '-c', run])
--------------------
To run this script, I use: sudo ~/test.py
I have 2 questions:

1) What should I add to the script to make it call itself ?
(It would then fall in the second branch of the "if" statement and run again the next day)

2) Would it still execute if the computer is restarted before the next run of the script ?
If not, I will try using the startup. Will it accept sudo ? gksu ? what else ?

PS: The command I am interested in is not really echo.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Locked

Return to “Beginner Questions”