在根incron作业中使用Zenity向当前登录的用户显示消息 [英] Using Zenity in a root incron job to display message to currently logged in user

查看:186
本文介绍了在根incron作业中使用Zenity向当前登录的用户显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用脚本自动上传位于目录中的文件,然后显示指向当前登录用户的链接。该机器的用户将通过LDAP进行身份验证。

Working on a script to auto-upload files that are placed in a directory, and then display a link to them to the currently logged in user. Users of the machine will be authenticated via LDAP.

incron正在监视的目录在任何用户的目录之外,并符号链接到/ home / username / uploads目录。当用户在此处放置文件时,系统会自动上传文件,而不会出现问题。

The directory that is being watched by incron is outside of any of the users' directories, and is symlinked to the /home/username/uploads directory for each user. When a user places a file here, it automatically uploads without issue.

当我遇到问题时,显示当前用户的文件URL。以下是相关代码:

Where I run into problems is displaying the file URL to the current user. Here's the relevant code:

来自/ var / spool / incron / root

from /var/spool/incron/root

/home/public/uploads IN_CLOSE_WRITE /home/public/upload_files.sh > /dev/null 2>&1

来自/home/public/upload_files.sh Zenity显示:

Lines from /home/public/upload_files.sh pertaining to Zenity display:

DISPLAY="$(ck-list-sessions | grep "active = TRUE" -A1 | tail -n 1 | cut -f2 -d"'").0"
zenity --info --text="http://aniceurlhere.com/`date +%m.%d.%y`/$filename" --display=$DISPLAY



如上所述,上传完成,但Zenity消息从不显示。查看/ var / log / cron,我可以看到作业运行并完成,没有显示错误。

As mentioned, the upload completes, but the Zenity message is never displayed. Looking through /var/log/cron, I can see the job run and complete, and no errors are shown there.

任何帮助将不胜感激。

Any assistance would be appreciated.

推荐答案

如果要使用zenity或notify-send,这需要一些工作。我没有得到它的工作,但我只是使用xmessage代替:

This takes a bit of effort if you want to use zenity or notify-send. I didn't get it working yet but I just used xmessage instead:

轻松的选项1:xmessage(在脚本中) >

Easy option 1: xmessage (in the script)

MSSG="/tmp/mssg-file-${RANDOM}" 
echo -e " MESSAGE \n ==========\n Done with task, YEY. " > ${MSSG}
xmessage -center -file ${MSSG} -display :0.0 
[[ -s ${MSSG} ]] && rm -f ${MSSG}

轻松选项2:设置DISPLAY )

    export DISPLAY=:0 && /usr/bin/somedirectory/somecommand

这篇关于在根incron作业中使用Zenity向当前登录的用户显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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