#!/bin/bash
#current system time and waketime
old=`date '+%H:%M'`
new=11:55
THISYEAR=`date +'%Y' -d 'now'`
NEXTMONTH=`date +'%m' -d 'next month'`
#if next month is January, increment the year by 1
if [ $NEXTMONTH == 01 ]
then
THISYEAR=`date +'%Y' -d '1 year'`
fi
#current system date and wake date(1st of next month)
olddate=`date +%Y-%m-%d`
newdate=$THISYEAR"-"$NEXTMONTH"-01"
IFS=: read old_hour old_min <<< "$old"
IFS=: read hour min <<< "$new"
# convert the date in seconds from Unix EPOCH time
sec_old=$(date -d "$olddate $old_hour:$old_min:00" +%s)
sec_new=$(date -d "$newdate $hour:$min:00" +%s)
DIFFERENCE=$(( (sec_new - sec_old) ))
#suspend the system and wake in this many seconds
sudo rtcwake -m mem -s $DIFFERENCE
Bookmarks