0

I am detecting IP assigned by dhclient and trying to show it using notify-send. I have made a script and placed it in /etc/dhcp/dhclient-exit-hooks.d. Content of the script is as below

#!/bin/bash
whoami >>/tmp/vari.txt
echo "========================>" >> /tmp/vari.txt
printenv >> /tmp/vari.txt
echo "========================>" >> /tmp/vari.txt
set >> /tmp/vari.txt
notify-send "hey"
MAINUSER=`cat /etc/passwd|grep 1000|sed "s/:.*$//g"`
su $MAINUSER -c $"notify-send \"IP assigned\""

I have saved it with name test and have given executable permission and root as owner. All the parts of the scripts are working except for notify-send. One thing I checked is keeping filename as test.sh and notify-send works from command line but dispatcher service doesn't execute it.

Can someone suggest a solution?

4
  • 1
    Try to put something like export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus before the su line.
    – FedKad
    Sep 21, 2020 at 9:08
  • thanks @FedonKadifeli but no luck. from command line notify-send runs but not via dhclient dispatch service. Sep 21, 2020 at 12:30
  • Is the user with id 1000 logged in to a GUI session by the time the script runs? There was a similar (not identical to yours) discussion here: askubuntu.com/questions/298608
    – FedKad
    Sep 21, 2020 at 12:44
  • @Fedonkadifeli MAINUSER variable in my script fetches the user with id 1000 and showing correct user not root. Will go through the link that you have provided Sep 22, 2020 at 5:39

0

You must log in to answer this question.

Browse other questions tagged .