Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #208376
| From | Dan Ritter <dsr@randomstring.org> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: notify-send script messed up my environment |
| Date | 2019-05-08 00:20 +0200 |
| Message-ID | <xVgBj-LU-3@gated-at.bofh.it> (permalink) |
| References | <xVfOW-fA-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Esteban L wrote:
> I stepped in poo, and broke a cardinal sin, trying a script that I
> didn't 100% understand. Now my environment is a little bit jacked. Not
> bad, still generally functioning.
>
> I was trying to get notifications to run from the command line, namely
> crontab. No easy task, at least, not as easy as I would have thought.
>
> I created and ran this script I found online:
> #!/bin/bash
> username=$(/usr/bin/whoami)
> pid=$(pgrep -u $username nautilus)
> dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed
> 's/DBUS_SESSION_BUS_ADDRESS=//' )
> export DBUS_SESSION_BUS_ADDRESS=$dbus
> /usr/bin/notify-send "$(today)"
>
> It seemed simple enough.
>
> It even worked a few half dozen times. Until, it didn't.
>
> I couldn't even run the script anymore, from the command line.
> I get the following error:
> grep: /proc/1700: Is a directory
> grep: 25836/environ: No such file or directory
>
> I tried to "man" up but can't find anything on dbus, dbus_session etc.
>
> I think it's as simple as messing up my environment.
>
> Can someone throw me a bone? I guess I could restart, and I assume that
> should work, but that doesn't really explain to me why it broke, which
> interests me more.
Let's go through the script and see if we can explain it.
#!/bin/bash
this is a bash script; please use /bin/bash to run it.
username=$(/usr/bin/whoami)
run the command /usr/bin/whoami and put the output in the
variable "username"
pid=$(pgrep -u $username nautilus)
run pgrep, look for a process named nautilus owned by that
username. Put the process ID in the variable "pid".
dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ | sed 's/DBUS_SESSION_BUS_ADDRESS=//' )
look through the contents of the file in /proc/ (process id)
/environ and find the line which contains the word
DBUS_SESSION_BUS_ADDRESS. pipe that line through the stream
editor to remove a bunch of characters and leave the rest.
Put the value in the variable "dbus".
export DBUS_SESSION_BUS_ADDRESS=$dbus
Make that "dbus" variable available to programs I run.
/usr/bin/notify-send "$(today)"
Run "notify-send" with a value that comes from a program
called "today".
Here are my suggestions:
Test running
/usr/bin/notify-send "Boo!"
If you get a notification, it's working. If not, you have deeper
problems.
Test with echo.
After each variable assignment, run
echo $username
or
echo $pid
and so forth, as appropriate, to see what values you are
getting.
Spaces and linebreaks are important.
"Nautilus" is not a foolproof way of knowing which X session is
wanted.
$(today) probably doesn't do what you want.
-dsr-
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
notify-send script messed up my environment Esteban L <esteban@little-beak.com> - 2019-05-07 23:30 +0200
Re: notify-send script messed up my environment Dan Ritter <dsr@randomstring.org> - 2019-05-08 00:20 +0200
Re: notify-send script messed up my environment Esteban L <esteban@little-beak.com> - 2019-05-08 01:20 +0200
Re: notify-send script messed up my environment Gene Heskett <gheskett@shentel.net> - 2019-05-08 01:50 +0200
Re: notify-send script messed up my environment Dan Ritter <dsr@randomstring.org> - 2019-05-08 02:00 +0200
Re: notify-send script messed up my environment Gene Heskett <gheskett@shentel.net> - 2019-05-08 03:50 +0200
Re: notify-send script messed up my environment Greg Wooledge <wooledg@eeg.ccf.org> - 2019-05-08 14:40 +0200
Re: notify-send script messed up my environment David Wright <deblis@lionunicorn.co.uk> - 2019-05-08 18:40 +0200
csiph-web