mem*_*und 5 bash cron notify-send 16.04
测试.sh: /usr/bin/notify-send "test"
以下工作: bash ~/Documents/test.sh
但是 crontab 从不显示通知。为什么?
*/1 * * * * bash ~/Documents/test.sh
要从 Cron 执行任何与 GUI 相关的应用程序,您应该导出一些桌面环境变量。以下解决方案基于此答案,其中提供了更多详细信息。
crontab
使用 Gnome从Ubuntu 16.04、17.10、18.04 和其他 Ubuntu 发行版启动任何与 GUI 相关的应用程序创建一个启动脚本,该脚本将导出桌面环境变量并启动您的应用程序。让我们称之为gui-launcher
。它的内容应该是(引用:[1] , [2]和[3]):
#!/bin/bash -e
# NAME: gui-launcher
# Check whether the user is logged-in
while [ -z "$(pgrep gnome-session -n -U $UID)" ]; do sleep 3; done
# Export the current desktop session environment variables
export $(xargs -0 -a "/proc/$(pgrep gnome-session -n -U $UID)/environ")
# Execute the input command
nohup "$@" >/dev/null 2>&1 &
exit 0
Run Code Online (Sandbox Code Playgroud)
gnome-session
在这部分更改为$(pgrep gnome-session -n -U $UID)
正在使用的 DE 进程的名称,例如mate-session
。此处提供了最多 Ubuntu DE 的列表。相同脚本的 Lubuntu 实现 -此处。该脚本可用于在当前用户的桌面会话中从 TTY 或 SSH 会话启动 GUI 应用程序。chmod +x gui-launcher
.然后crontab
以这种方式使用它:
*/1 * * * * /full/path/to/gui-launcher "/full/path/to/the-targer-application"
Run Code Online (Sandbox Code Playgroud)
以下是它在 Wayland 上的 Ubuntu 17.10 上的工作方式:
下面是通过 SSH 实现相同脚本的一个实现:How to run script (.sh) files in a new terminal after connected to Ubuntu 16.04 server via ssh?
这里提供了更多解释:在重启时运行 python 脚本的 Cron 作业不起作用。
还有一个例子:使用 xrandr 和 cron 作业调整亮度
归档时间: |
|
查看次数: |
3363 次 |
最近记录: |