我有一个基本的 bash 脚本,用于检查系统是否空闲超过一个小时,如果是,则将其关闭:
#!/bin/bash
while true; do
get_idle_time=`dbus-send --print-reply --dest=org.gnome.Mutter.IdleMonitor /org/gnome/Mutter/IdleMonitor/Core org.gnome.Mutter.IdleMonitor.GetIdletime`
idle_time=$(echo $get_idle_time | awk '{print $NF}')
if [[ $idle_time -ge 3600000 ]]; then
shutdown
fi
done
我添加了这个脚本,/etc/rc.local
所以它总是处于活动状态:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
bash /home/paulky/shutdown.sh
exit 0
虽然bash /home/paulky/shutdown.sh
在我登录时从终端工作,但这样做/etc/rc.local
似乎会阻止 Ubuntu 进入登录屏幕,并F2显示此错误消息无限重复:
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11.
我已经尝试export DISPLAY=:0
在脚本开始之前添加,但无济于事。