Using Zenity in a root incron job to display message to currently logged in user

不羁的心 提交于 2019-12-13 18:26:58

问题


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.

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.

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

from /var/spool/incron/root

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

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

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.


回答1:


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:

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}

Easy option 2: set the DISPLAY (then should work)

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


来源:https://stackoverflow.com/questions/23706194/using-zenity-in-a-root-incron-job-to-display-message-to-currently-logged-in-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!