我正在尝试使用以下唤醒脚本,我发现这里,让我的电脑在晚上进入睡眠状态并在早上唤醒它。该脚本使用唤醒:
#!/bin/bash
# Auto suspend and wake-up script
#
# Puts the computer on standby and automatically wakes it up at specified time
#
# Written by Romke van der Meulen <[email protected]>
# Minor mods fossfreedom for AskUbuntu
#
# Takes a 24hour time HH:MM as its argument
# Example:
# suspend_until 9:30
# suspend_until 18:45
# ------------------------------------------------------
# Argument check
if [ $# -lt 1 ]; then
echo "Usage: suspend_until HH:MM"
exit
fi
# Check whether specified time today or tomorrow
DESIRED=$((`date +%s -d "$1"`))
NOW=$((`date +%s`))
if [ $DESIRED -lt $NOW ]; then
DESIRED=$((`date +%s -d "$1"` + 24*60*60))
fi
# Kill rtcwake if already running
sudo killall rtcwake
# Set RTC wakeup time
# N.B. change "mem" for the suspend option
# find this by "man rtcwake"
sudo rtcwake -l -m mem -t $DESIRED &
# feedback
echo "Suspending..."
# give rtcwake some time to make its stuff
sleep 2
# then suspend
# N.B. dont usually require this bit
#sudo pm-suspend
# Any commands you want to launch after wakeup can be placed here
# Remember: sudo may have expired by now
# Wake up with monitor enabled N.B. change "on" for "off" if
# you want the monitor to be disabled on wake
xset dpms force on
# and a fresh console
clear
echo "Good morning!"
当我从命令行手动运行该脚本时,它工作正常,但当作为 cronjob 运行时,它永远不会关闭计算机。crontab 命令如下:
02 10 * * * /home/***/bin/suspend_until 10:03 >> /home/ethan/log/suspend.log 2>$1
日志是空的,所以我无法确切知道发生了什么。有什么想法吗?
答案1
解决方案是使用 sudo:sudo crontab -e'