Re: 如何关机?
发表于 : 2010-06-17 9:29
Z想干嘛
有问题找 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
抱歉,刚才到 Ubuntu 10.04 中找一下,gnome-power-manager 软件包中确实不包含 gnome-power-cmd,Debian 5.0 中是包含的。pocoyo 写了:没这个命令.
代码: 全选
#!/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
代码: 全选
# !/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
aerofox 的就是了,使用 dbus 发个关机信号,没其它用户登录的话就立即给你关机了。罗非鱼 写了:各位谈呢这么多都没有到点子上,请问,linux(或者说ubuntu10.04)中,普通用户(没有root密码),可否用命令行关闭计算机??
你才不务实呢!普通用户可以发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
}