如何关机?
-
- 帖子: 1453
- 注册时间: 2008-05-24 8:30
Re: 如何关机?
有问题找 man 的想法不错,但是这个命令恰好是没有 manpage 的,不能因为没有 man 就断定不存在这个命令吧?为什么不直接试一下命令呢?罗非鱼 写了:pt@pt-laptop:~$ sudo apt-get install gnome-power-manager
[sudo] password for pt:
Reading package lists... Done
Building dependency tree
Reading state information... Done
gnome-power-manager is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.
pt@pt-laptop:~$ man gnome-power-cmd
No manual entry for gnome-power-cmd
-
- 帖子: 1453
- 注册时间: 2008-05-24 8:30
Re: 如何关机?
Debian 中的 gnome-power-cmd 命令是个脚本文件,内容如下,估计放到 Ubuntu 中也可以用:
代码: 全选
#!/bin/sh
# Copyright (C) 2007 Richard Hughes <[email protected]>
#
# Licensed under the GNU General Public License Version 2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#$1 = method name
execute_dbus_method ()
{
dbus-send --session --dest=org.freedesktop.PowerManagement \
--type=method_call --print-reply --reply-timeout=2000 \
/org/freedesktop/PowerManagement \
org.freedesktop.PowerManagement.$1
if [ $? -eq 0 ]; then
echo "Failed"
fi
}
if [ "$1" = "suspend" ]; then
echo "Suspending"
execute_dbus_method "Suspend"
elif [ "$1" = "hibernate" ]; then
echo "Hibernating"
execute_dbus_method "Hibernate"
elif [ "$1" = "reboot" ]; then
echo "Rebooting"
execute_dbus_method "Reboot"
elif [ "$1" = "shutdown" ]; then
echo "Shutting down"
execute_dbus_method "Shutdown"
elif [ "$1" = "" ]; then
echo "command required: suspend, shutdown, hibernate or reboot"
else
echo "command '$1' not recognised, only suspend, shutdown, hibernate or reboot are valid"
exit 1
fi
-
- 帖子: 598
- 注册时间: 2009-09-19 20:50
Re: 如何关机?
我说的很清楚了
保存为 TestShutDown.sh
然后
再执行 sudo -k 清除 sudo 密码缓存
只有 TestShutDown.sh 会以 root 执行。而你原来的脚本并没有 root 权限。另外修改 TestShutDown.sh 也需要 root 权限,这样就可以防止 root 权限被盗用。
代码: 全选
# !/bin/bash
do
if [ -e "~/shutdownLock" ]; then
sleep 10
else
shutdown -h now
fi
done
然后
代码: 全选
chmod u+x TestShutDown.sh
sudo chown root\: TestShutDown.sh
sudo ./TestShutDown.sh
只有 TestShutDown.sh 会以 root 执行。而你原来的脚本并没有 root 权限。另外修改 TestShutDown.sh 也需要 root 权限,这样就可以防止 root 权限被盗用。
aMule 2.3.1 is coming...
真正动态的 amule-dlp is coming...
本人帐号在2011年1月被盗,在2011年1月3日17:19到2010年1月6日13:34之间本帐号发的一切帖子、短信等与本人无关!
amule-dlp 开发动态
amule-dlp on Google Code
WebArchiver - 基于 wget 的网页归档工具(PyQt4 GUI 前端)
Linux 2.6.34 编译笔记
真正动态的 amule-dlp is coming...
本人帐号在2011年1月被盗,在2011年1月3日17:19到2010年1月6日13:34之间本帐号发的一切帖子、短信等与本人无关!
amule-dlp 开发动态
amule-dlp on Google Code
WebArchiver - 基于 wget 的网页归档工具(PyQt4 GUI 前端)
Linux 2.6.34 编译笔记
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: 如何关机?
你才不务实呢!普通用户可以发dbus消息!以下是我的关机函数:罗非鱼 写了:这帮回帖的,一个比一个不务实,我的前提条件是,没有sudo 的密码,没有root密码,普通用户根本不能使用那些命令!
代码: 全选
shutdown () { #{{{2
echo -n 你确定要关机吗?
read i
if [ $i = "y" -o $i = "是" ]
then
dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
fi
}