You are not logged in.
Pages: 1
Hi
I have the following scripts to wake up the pc and play music in /usr/local/bin
alarmset
#!/bin/bash
#/usr/local/bin
if [ -v 1 ]; then
echo "" >> /dev/null
else
echo 'Enter a time for the alarm in the format "MM-DD-YYYY HHMM". See -h for help.'
exit
fi
if [ $1 == "-h" ]; then
echo 'Set the alarm for when the computer wakes up from sleep and plays music. Enter "MM-DD-YYYY HHMM" to set the alarm. Time format is 24-hour.'
echo ''
echo 'See if an alarm is with "--when".'
echo 'Reset an alarm with "--reset".'
exit
fi
if [ $1 == "--when" ]; then
sudo alarmsetpermission --returnalarmdate
exit
fi
if [ $1 == "--reset" ]; then
sudo alarmsetpermission --reset
echo "No alarm set"
exit
fi
if [ -v 1 ]; then
varname_date=$1
date1a=${varname_date:0:2}
date2a=${varname_date:3:2}
date3a=${varname_date:6:4}
shopt -s extglob
if [[ -z "${date1a##+([0-9])}" && -z "${date3a##+([0-9])}" && -z "${date2a##+([0-9])}" ]]; then
if [ ${#varname_date} == 10 ]; then
date1=$((10#$date1a))
date2=$((10#$date2a))
date3=$((10#$date3a))
if [[ $date1 -gt -1 && $date1 -lt 13 && $date2 -gt -1 && $date2 -lt 32 && $date3 -gt 2021 && $date3 -lt 2099 ]]; then
:
else
echo "MM month is an integer between 01 and 12. DD day is an integer between 00 and 31. YYYY is an integer, i.e. 2022"
exit
fi
else
echo 'Enter a time for the alarm in the format "MM-DD-YYYY HHMM". See -h for help.'
exit
fi
else
echo 'Enter a time for the alarm in the format "MM-DD-YYYY HHMM". See -h for help.'
exit
fi
fi
if [ -v 2 ]; then
varname=$2
shopt -s extglob
if [ -z "${varname##+([0-9])}" ]; then
if [ ${#varname} == 4 ]; then
time1a=${varname:0:2}
time2a=${varname:2:2}
time1=$((10#$time1a))
time2=$((10#$time2a))
if [[ $time1 -gt -1 && $time1 -lt 25 && $time2 -gt -1 && $time2 -lt 60 ]]; then
if [[ $(date "+%s" -d "$date1/$date2/$date3 $time1:$time2") -lt $(date "+%s") ]]; then
echo "No alarm set. Current time is after the chosen alarm time."
exit
fi
untilalarm=$(($(date "+%s" -d "$date1/$date2/$date3 $time1:$time2") - $(date "+%s")))
sudo alarmsetpermission --reset
sleep 1s
sudo alarmsetpermission $date1 $date2 $date3 $time1 $time2 &
alarmsetplay $date1 $date2 $date3 $time1 $time2 &
disown;
echo $(date "+Alarm set for: %A %H:%M on the %d of %B, %Y (%m/%d/%y %H:%M)" -d "$date1/$date2/$date3 $time1:$time2")
echo ""
echo $(date -ud "@$untilalarm" +"%H hour(s) and %M minute(s) until alarm.")
exit
else
echo "HH hour-format is in integer 00-24 and MM minutes is in integer 00-59."
exit
fi
else
echo 'Enter a time for the alarm in the format "MM-DD-YYYY HHMM". See -h for help.'
exit
fi
else
echo 'Enter a time for the alarm in the format "MM-DD-YYYY HHMM". See -h for help.'
exit
fi
else
echo 'Enter a time for the alarm in the format "MM-DD-YYYY HHMM". See -h for help.'
fialarmsetpermission (/usr/local/bin/alarmsetpermission added with nopasswd in sudoer)
#/bin/bash!
if [ $1 == "--reset" ]; then
echo "0" > /sys/class/rtc/rtc0/wakealarm
killall alarmsetplay 2>/dev/null
elif [ $1 == "--returnalarmdate" ]; then
activealarmdate=$(cat /sys/class/rtc/rtc0/wakealarm)
if [ "$activealarmdate" == "" ]; then
echo 'No alarm set'
else
echo $(date "+Alarm set for: %A %H:%M on the %d of %B, %Y (%m/%d/%y %H:%M)" -d "@$activealarmdate")
echo ""
untilalarm=$(($activealarmdate - $(date "+%s")))
echo $(date -ud "@$untilalarm" +"%H hour(s) and %M minute(s) until alarm.")
fi
else
echo $(date '+%s' -d "$1/$2/$3 $4:$5") > /sys/class/rtc/rtc0/wakealarm
fialarmsetplay
#!/bin/bash
#/usr/local/bin
echo $1 > ~/.local/share/alarmset
echo $2 >> ~/.local/share/alarmset
echo $3 >> ~/.local/share/alarmset
echo $4 >> ~/.local/share/alarmset
echo $5 >> ~/.local/share/alarmset
while true; do
varname1=$(sed -n '1p' ~/.local/share/alarmset)
date1a=${varname1}
varname2=$(sed -n '2p' ~/.local/share/alarmset)
date2a=${varname2}
varname3=$(sed -n '3p' ~/.local/share/alarmset)
date3a=${varname3}
varname4=$(sed -n '4p' ~/.local/share/alarmset)
time1a=${varname4}
varname5=$(sed -n '5p' ~/.local/share/alarmset)
time2a=${varname5}
date1=$((10#$date1a))
date2=$((10#$date2a))
date3=$((10#$date3a))
time1=$((10#$time1a))
time2=$((10#$time2a))
if [[ $(date '+%s') -gt $(date '+%s' -d "$date1/$date2/$date3 $time1:$time2") ]]; then
sleep 5s
mpv --playlist="/home/username/Music/alarmset" --shuffle --no-sub-visibility --no-video --loop-playlist &
sleep 1s
disablesleep=$(pidof mpv)
while true; do
if [[ "$disablesleep" == "" ]]; then
exit
else
xdotool mousemove_relative -- -1 -1
sleep 5m
xdotool mousemove_relative -- 1 1
disablesleep=$(pidof mpv)
fi
done
else
sleep 1m
fi
doneIt has been working flawlessly for waking me up in the morning to my big enjoyment. After a recent update, it has stopped working.
The alarm will work if I set it to a couple of hours in the future, but if I set it to a time i.e. 12 hours in the future, it will not work. The pc will crash and can't manually wake up the machine and have to do a hard reset.
I am not sure, but I don't think that alarmtimer.0.auto was in /sys/class/rtc/rtc0 before:
ls /sys/class/rtc/rtc0
alarmtimer.0.auto date dev device hctosys max_user_freq name power since_epoch subsystem time uevent wakealarmI don't know how to debug it. Maybe someone knows what the problem is?
Best regards,
Adam
EDIT:
Wrong code in initial post for alarmsetpermission
SOLUTION:
I have grub-customizer installed. I opened grub-customizer, it said that new scripts were detected, pressed save, rebooted and now the pc can sleep for extended periods. Didn't do this when the pc was initially updated.
Last edited by adam87 (2022-05-26 04:54:01)
Offline
The code just echoes the date for the RTC wake up in epoch time to /sys/class/rtc/rtc0/wakealarm.
My last update before my most recent update was 2 - 3 months ago and I changed the bios battery in the meantime. It worked fine after this, also, there is power to the pc at all times. I updated a couple of days ago and around the same time the bios got flashed, but I think it worked normally after this and the RTC is set to managed by OS as default in the bios + RTC wakes up correctly when it is set to a short time frame, so I don't think that it is a hardware problem.
EDIT:
For the music to start playing after the RTC has waken the computer up, the variables must be saved to the disk. So it does this in alarmsetplay, but doesn't use them here:
if [[ $(date '+%s') -gt $(date '+%s' -d "$1/$2/$3 $4:$5") ]]; thenSo this should be changed to:
if [[ $(date '+%s') -gt $(date '+%s' -d "$date1/$date2/$date3 $time1:$time2") ]]; thenDoesn't explain why the pc goes into a hardlock when it presumably goes back to sleep when there is no music playing. I will try it now for tomorrow.
EDIT:
The problem is related to a recent update or an error with the bios, and not the script I am using. If the pc goes to sleep for a longer period of time, i.e. >1 hour, it cannot wake up and a hard reset has to be done.
Will probably have to reinstall and reset the bios at some point to get it working.
Last edited by adam87 (2022-05-25 17:09:25)
Offline
Pages: 1