-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwakeat
executable file
·45 lines (33 loc) · 1.04 KB
/
wakeat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
# Fernando Carmona Varo <[email protected]
#----
# Sets the computer in suspension (to memory)
# and sets it to automatically wake up at the given time.
#----
[ -z "$1" ] && {
echo "usage: ${0##*/} <time>"
exit
}
etime=$(date -d "$@" +%s)
time=$(date -d "$@" +"%D %T")
[ -z $etime ] && exit
echo "Going to sleep! the system will wake aproximately at ${time}."
echo "Press any key to continue, Ctr-C to abort."
read p
now=$(date -d "now" +%s)
if [ $etime -lt $now ]
then
echo "Please provide a time that is not in the past! (current date: $(date '+%D %T'))"
exit 1
elif [ $((etime - now)) -lt $((4 * 60)) ]
then
echo "The waking time might have a short window to be triggered in some systems."
echo "This means the waking time might be earlier than the one specified by a few minutes."
echo "Please choose an interval of at least 4 minutes into the future to prevent issues."
exit 1
fi
[ -w /sys/power/state ] || {
echo "/sys/power/state: not writable, sudoing"
cmd="sudo"
}
$cmd rtcwake -m "${MODE:-mem}" -vt ${etime}