在openbox中用脚本重启、登出、关机

装了openbox之后发现一个问题,没有方便的关机方式,只能在终端用sudo poweroff。最近研究了下zenity,写了个简单的脚本来完成这个工作。

#!/bin/bash
ans=$(zenity --list --title "Make your choice" --text "What should I do?"\
--radiolist --column "Choice" --column "Action" \
reboot reboot logout logout poweroff poweroff);
echo $ans
case $ans in
'reboot')
echo "reboot"
sudo reboot
;;
'logout')
echo "logout"
killall openbox
;;
'poweroff')
echo "poweroff"
sudo poweroff
;;
esac

将以上内容保存成文件,加上可执行权限即可。首先需要保证系统中有zenity,并且在sudoers文件中设置poweroff以及reboot命令不需要密码。具体方法是:执行visudo,在配置文件最后加入:

ALL ALL=NOPASSWD:/sbin/poweroff
ALL ALL=NOPASSWD:/sbin/reboot

Enjoy~

如果你喜欢这篇日志的话,欢迎订阅我的RSS Feed!
本文来源于一阁Blog。版权所有,转载请确保已阅读该页面

2 Responses to “在openbox中用脚本重启、登出、关机”


  1. 1 quark

    赞!
    gdialog确实好用~~

  2. 2 yegle

    赞!
    gdialog确实好用~~

    好多的依赖关系啊……特地从/home分到/的2G空间瞬间只剩下500M了……

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

Quote selected text