问题
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