rc.local issues / workaround doesn't allow notify-send?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Luno

rc.local issues / workaround doesn't allow notify-send?

Post by Luno »

Hi,

In Linux Mint 17, I had a little script that I executed at startup via an entry in rc.local. Its purpose is to wait for my generic game controller to be plugged in, which it then maps to xboxdrv and deletes everything but the fake xbox-Controller from the jsX device list. If everything goes well, "notify-send" should pop a notification. Since it messes with /dev/input, the script needs to be root.

In Linux Mint 18, this still kinda works, but only after moving the script call from rc.local to a crontab @reboot entry - otherwise, my system would not boot at all, which was funny to even find out, because boot decided to just stop while the last line displayed was "Starting ntp service" *____*

Anyways, now via crontab, while not having altered the script itself, even with a successful controller configuration, "notify-send" does not seem to work anymore?

I realize it's basically a non-issue buuuut in any case any hinty hints much appreciated :wink:
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: rc.local issues / workaround doesn't allow notify-send?

Post by Pilosopong Tasyo »

Does the script run via root's crontab sudo crontab -e or local crontab crontab -e ? Educated guess is the former since your script requires elevated privileges to run successfully.

IMSMR, when I needed to run a script as root and have to show a message to a non-root logged-in user via notify-send, I tell the system to run notify-send as the local user (for the sake of example, let's use your username in this forum) as well as set the DISPLAY environment variable (notify-send requires this to be defined). Something like:

Code: Select all

sudo -u luno DISPLAY=:0.0 /usr/bin/notify-send "title" "description blah blah blah..."
Another approach (from what I read years ago) is to use DBUS to display 'notify-send' messages on screen regardless what user is logged into the GUI. I never pursued this approach, however. You'll have to do some research. :wink:
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
Locked

Return to “Scripts & Bash”