Linux关闭与dbus发送 [英] Linux Shutdown with dbus-send

查看:871
本文介绍了Linux关闭与dbus发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Java应用程序来远程关闭我的Linux文件夹。

I am writing a Java app to shutdown my Linux box remotely.

桌面应用程序就位,并等待发送命令。我已经尝试使用shutdown -h,但这需要sudo权限,不是一个选项。然后我找到了一种方法,使用下面的dbus-send解决方案关闭没有sudo:

The desktop app sits and waits for a command to be sent to it. I have tried using "shutdown -h" but this requires sudo privileges and is not an option. I then found a way to shutdown without sudo using the following dbus-send solution:

dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown

这工作正常,但我想弄清楚,使用dbus-send,如果它可能做一个定时关机类似于关闭3600,这将关闭电脑在1小时?

This works fine but I am trying to figure out, using dbus-send, if its possible to do a timed shutdown similar to "shutdown 3600" which would shut the computer down in 1 hour?

干杯

Eef

推荐答案

HAL,您正在呼叫的功能,不提供此功能。但是你可以随时用这样的东西,如果你正在启动一个外部命令:

HAL, which function you are calling, does not provide this feature. But you can always go with something like this, if you are launching an external command anyway:

sh -c "sleep 1h; dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown"

这篇关于Linux关闭与dbus发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆