linux - i3blocks (i3wm) - 使用 sudo 命令

标签 linux bash ubuntu

<分区>

我正在为 i3wm 配置我的 i3blocks,但我似乎无法执行如下 sudo 命令:

[update-notifier]
label=UPDATE
command=sudo ~/.i3/scripts/update-notifier.sh
interval=once

在 update-notifier.sh 文件中我有这个:

apt-get update && apt-get upgrade

加上一些用于格式化 i3blocks 栏的 echo。 我试过这个:

  • command=sudo ~/.i3/scripts/update-notifier.sh 使用和不使用 apt-get 的 sudo -> 脚本不启动
  • command=sudo apt-get update && sudo apt-get upgrade -> 命令未执行
  • command=~/.i3/scripts/update-notifier.sh 带有 apt-get 的 sudo -> 脚本启动,i3bar 格式正确,但 apt-get 不是t 执行。

最佳答案

您是否配置了 sudo,以便它不会使用 apt-get 命令向您的用户询问密码?也许您的命令正在运行,但它要求输入密码但失败了。

我能够通过允许我的用户使用 sudo 运行 apt-get 而无需密码将其添加到 /etc/sudoers 文件来完成您正在尝试做的事情:

<my-user> <my-host> = (root) NOPASSWD:/usr/bin/apt-get

然后添加一个带有 command 属性设置的 block ,就像您的第二个选项一样:

command=sudo apt-get update

并通过重新加载 i3 并检查我最新更新的时间戳来验证它是否有效:

stat -c %y /var/lib/apt/periodic/update-success-stamp

这表明最近成功完成了最近的更新:

2015-10-13 08:29:30.996348567 -0430

关于linux - i3blocks (i3wm) - 使用 sudo 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32691581/

相关文章:

linux - grep 包含 1 个字符后跟另一个字符的行

linux - 在两个字符串语句之间插入新字符串

Ubuntu 下载一个包及其所有依赖项而不安装它们

python - 一旦 python 脚本从终端 (Ctrl-C) 停止,如何释放 Ubuntu 内存?

python - `pygame` : on Ubuntu, 使用 `pygame.image.save` 保存 PNG 导致 `pygame.error: SavePNG: could not create png write struct`

Django-Deterministic = True在运行python manage.py runserver时需要SQLite 3.8.3或更高版本

linux - 什么时候应该重新编译手动编译的程序?

c - 比较c中的两个char指针值时strcmp返回true

bash - "jq: error: Cannot index array with string"使用jq从ElasticSearch结果中获取数据

linux - 哪个配置文件将登录密码原始文本转换为 Linux 中的哈希值?