当前位置:首页 » 编程软件 » ubuntu关机脚本

ubuntu关机脚本

发布时间: 2023-05-14 14:45:46

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年前的老电脑,
它们的关机键,就是一个简单的电源开关,与拔电源的效果是一样的,
瞬间断电,
对于现在的电源管理方式,没有权威的人提出这个,没有必要,成为一种固定模式了,
教材也一直沿用以前的说法

热点内容
c语言编程与设计 发布:2025-09-18 06:09:15 浏览:716
2016年预算法 发布:2025-09-18 06:07:05 浏览:617
什么是广告脚本设计 发布:2025-09-18 05:52:09 浏览:653
移动版我的世界服务器 发布:2025-09-18 05:38:49 浏览:960
使用jsp脚本输出九九乘法表 发布:2025-09-18 05:22:11 浏览:665
出行解压 发布:2025-09-18 05:20:54 浏览:576
安卓手机画线怎么用 发布:2025-09-18 05:16:43 浏览:699
解压吃蔬菜 发布:2025-09-18 05:10:04 浏览:820
php判断数组个数 发布:2025-09-18 04:54:02 浏览:666
linuxmd5c 发布:2025-09-18 04:47:04 浏览:346