gpt4 book ai didi

linux - 网络管理器调度程序脚本无法重新启动很棒的 wm

转载 作者:太空宇宙 更新时间:2023-11-04 03:59:00 32 4
gpt4 key购买 nike

我希望当网络环境改变时,awesome wm 能够以不同的配置运行。因此我在网络管理调度程序中编写了一个脚本,以便当网络环境发生变化时执行该脚本;

#!/bin/bash
# Restart awesome through awesome-client

USER=dreamingo

awesome_restart(){
/bin/su $USER -c "echo 'local awful = require (\"awful\"); return awful.util.restart()' | awesome-client"
}

#To check the cable insert or not
wire_insert_state=$(cat /sys/class/net/eth0/carrier)
#Check which config the current awesome taking(wired or wireless)
current_config=$(cat ~/.config/awesome/flag)

# if [[ $wire_insert_state = 1 ]] && [[ $current_config == "wireless" ]];then
if [[ $wire_insert_state = 1 ]];then
cp /home/dreamingo/.config/awesome/rc.lua.wire /home/dreamingo/.config/awesome/rc.lua
echo wired > ~/.config/awesome/flag
awesome_restart

# elif [[ $wire_insert_state = 0 ]] && [[ $current_config == "wired" ]];then
elif [[ $wire_insert_state = 0 ]];then
cp /home/dreamingo/.config/awesome/rc.lua.wireless /home/dreamingo/.config/awesome/rc.lua
echo wireless > ~/.config/awesome/flag
awesome_restart
fi

但是,当环境发生变化时,这个脚本确实会运行,但 Awesome wm 不会重新启动。

我认为这是脚本由root执行的原因,因此我使用以下命令:

/bin/su $USER -c "echo 'local awful = require (\"awful\"); return awful.util.restart()' | awesome-client"

当我su到root时,这个命令将起作用(重新启动很棒的wm);但是,当我使用时:

sudo ./02check_wireless    #02check_wireless was the name of the script

运行脚本,脚本失败重启wm;但是当我以当前用户(dreamingo)身份运行它时,它就可以工作;

而且,无论是上述结果(成功与否),脚本都会输出:

Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.naquadah.awesome.awful was not provided by any .service files

我以为失败的也尝试重新启动真棒,但有东西覆盖或阻止它......

最佳答案

当我以 root 身份运行它时,这个变体对我来说效果很好,具有很棒的 3.5.5

#!/bin/bash
# Restart awesome through awesome-client

USER=my_username_here

awesome_restart(){
/bin/su $USER -c "echo 'awesome.restart()' | awesome-client"
}

awesome_restart

关于linux - 网络管理器调度程序脚本无法重新启动很棒的 wm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23723557/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com