ubuntu關機腳本
⑴ linux系統怎麼關機
直接按開機的電源鍵。
linux下,按 電源鍵會產生關機消息,接收消息的腳本會調用關機命令關機,與手動輸入關機命令,或者使用滑鼠點擊菜單,對話框關機的過程是完全一樣的。
我在win7,winxp下也是,很方便,它們都和菜單,對話框的關機效果一樣。
我使用的是ubuntu12.04 server版,系統中電源鍵關機腳本是
其它linux發行版也差不多,都有自己的處理腳本
/etc/acpi/powerbtn.sh
#!/bin/sh
# /etc/acpi/powerbtn.sh
# Initiates a shutdown when the power putton has been
# pressed.
[ -r /usr/share/acpi-support/power-funcs ] && . /usr/share/acpi-support/power-funcs
# getXuser gets the X user belonging to the display in $displaynum.
# If you want the foreground X user, use getXconsole!
getXuser() {
user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
if [ x"$user" = x"" ]; then
startx=`pgrep -n startx`
if [ x"$startx" != x"" ]; then
user=`ps -o user --no-headers $startx`
fi
fi
if [ x"$user" != x"" ]; then
userhome=`getent passwd $user | cut -d: -f6`
export XAUTHORITY=$userhome/.Xauthority
else
export XAUTHORITY=""
fi
export XUSER=$user
}
# Skip if we just in the middle of resuming.
test -f /var/lock/acpisleep && exit 0
# If the current X console user is running a power management daemon that
# handles suspend/resume requests, let them handle policy This is effectively
# the same as 'acpi-support's '/usr/share/acpi-support/policy-funcs' file.
[ -r /usr/share/acpi-support/power-funcs ] && getXconsole
PMS="gnome-settings-daemon kpowersave xfce4-power-manager"
PMS="$PMS guidance-power-manager.py dalston-power-applet"
if pidof x $PMS > /dev/null; then
exit
elif test "$XUSER" != "" && pidof dcopserver > /dev/null && test -x /usr/bin/dcop && /usr/bin/dcop --user $XUSER kded kded loadedMoles | grep -q klaptopdaemon; then
exit
elif test "$XUSER" != "" && test -x /usr/bin/qdbus; then
kded4pid=$(pgrep -n -u $XUSER kded4)
if test "$kded4pid" != ""; then
dbusaddr=$(su - $XUSER -c "grep -z DBUS_SESSION_BUS_ADDRESS /proc/$kded4pid/environ")
if test "$dbusaddr" != "" && su - $XUSER -c "export $dbusaddr; qdbus org.kde.kded" | grep -q powerdevil; then
exit
fi
fi
fi
# If all else failed, just initiate a plain shutdown.
/sbin/shutdown -h now "Power button pressed"
所謂的不能直接按電源鍵關機的說法,是15年前的老電腦,
它們的關機鍵,就是一個簡單的電源開關,與拔電源的效果是一樣的,
瞬間斷電,
對於現在的電源管理方式,沒有權威的人提出這個,沒有必要,成為一種固定模式了,
教材也一直沿用以前的說法