0

I have the following script:

#!/bin/sh

notificationMessage="Your session is going to expire soon"
if [ $# == 2 ]; then
  notificationMessage="Your session is going to expire in $2 hour"
fi

# echo "$notificationMessage"

sudo -u userA notify-send "Session Expiration Notification" "$notificationMessage" -u normal -t 10000

When I run the above script from a terminal (logged in as remoteUser), userA is able to see the notification on the screen. However, if the script is executed from a service (run as remoteUser), the notification is not shown to userA.

Where am I doing things wrong?

Note: remoteUser has sudo privilege

1 Answer 1

0

However, if the script is being executed from a service (run as remoteUser), the notification is not shown to the userA.

X.org by default limits access to itself to a single active user session. There are different ways to solve this issue:

  1. Using export DISPLAY=:0 and sudo your_currentuser notification_command
  2. Running xhost +SI:localuser:remoteUser under your user session to allow remoteUser to run X applications in your session. In your script you will still have to use export DISPLAY=:0

More info:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .