rephorm / xuserrun

Run commands as the currently-active X11 user
The Unlicense
28 stars 8 forks source link

Doesn't work if running from cron #5

Open rubo77 opened 10 years ago

rubo77 commented 10 years ago

I tried to run this script from cron.hourly:

#!/bin/bash
/usr/local/bin/xuserrun notify-send "starting some scan... "
#...

It runs fine if I run it as root in a terminal inside my window manager (lightdm on buntu 1404) but it doesnt give out a notification if I run it from cron

I tried to find a solution to http://unix.stackexchange.com/questions/162492/create-a-notification-on-the-screen-initiated-by-root?noredirect=1#comment266182_162492

rephorm commented 10 years ago

Hey, this script was quickly thrown together, I only ever tested it on arch linux, and I haven't used it in over a year (so things may have changed). If you only care about one user and the value of $DISPLAY is constant for that user (e.g., ":0"), then you can just try:

DISPLAY=":0" su -c - $USER "$CMD"

On Thu, Oct 16, 2014 at 6:00 AM, Ruben Barkow notifications@github.com wrote:

I tried to run this script from cron.hourly:

!/bin/bash

/usr/local/bin/xuserrun notify-send "starting rkhunter scan... " rkhunter --checkall --report-warnings-only | while read OUTPUT; do if [ "$OUTPUT" != "" ]; then OUTPUT="${OUTPUT//[`\"\']/}" /usr/local/bin/xuserrun notify-send "rkhunter: $OUTPUT" fi done

It runs fine if I run it as root in a terminal inside my window manager (lightdm on buntu 1404) but it doesnt give out a notification if I run it from cron

I tried to find a solution to http://unix.stackexchange.com/questions/162492/create-a-notification-on-the-screen-initiated-by-root?noredirect=1#comment266182_162492

— Reply to this email directly or view it on GitHub https://github.com/rephorm/xuserrun/issues/5.

rubo77 commented 10 years ago

I found out, you need the correct DBUS sessiion which changes every login.

Here is a solution that works on Ubuntu: http://askubuntu.com/questions/536762/run-rkhunter-regularely-on-a-desktop-system/537721#537721