Skip to main content
Topic: Notification from Cronjobs not working (Read 2171 times) previous topic - next topic
0 Members and 7 Guests are viewing this topic.

Re: Notification from Cronjobs not working

Reply #15
The info from the x-session needs to be available to the cronjob script.
So you might run this as a script at your x-session login:
Code: [Select]
echo 'export DBUS_SESSION_BUS_ADDRESS='$DBUS_SESSION_BUS_ADDRESS > /tmp/dsba
chmod +x /tmp/dsba
And in the crontob script run /tmp/dsba before sending out the notification


 

Re: Notification from Cronjobs not working

Reply #17
@strajder  why link it? did you even read https://forum.artixlinux.org/index.php/topic,2988.msg19398.html#msg19398  ? ? ?
i have posted all important stuff.
Quote
This doesn't explain how the line works on my system, but not for the OP.
that is indeed a mystery!!!   :D  :D

@Artist  that is a very nice trick!

Right now, i am trying to make it work, `cp -f /usr/share/dbus-1/session.conf .config/dbus-session.conf` and then change
one important lie:
Code: [Select]
$ diff /usr/share/dbus-1/session.conf .config/dbus-session.conf
15c15
<   <listen>unix:tmpdir=/tmp</listen>
---
>   <listen>unix:path=/tmp/dbus-dontchange</listen>
as i was told by carlos in the artix telegram group.
if that wont work, @Artist  i will use your method.
Thanks a lot

Re: Notification from Cronjobs not working

Reply #18

i have been told, in the artix wiki and artix telegram group that  i should use `dbus-launch --exit-with-session dwm` instead of `exec dwm`.
Where in the Artix wiki? Provide a link.

I repeat:
https://wiki.archlinux.org/title/Xinit#xinitrc
Quote
Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an & sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of xrdb. Prepending exec will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.

https://dwm.suckless.org/tutorial/
Quote
Launching
To launch dwm, ideally you should setup a ~/.xinitrc with at least exec dwm.

Re: Notification from Cronjobs not working

Reply #19
@strajder  aaaah i thought u wanted to link my xprofile file, thats why i said i have posted it.
for dbus launch
https://wiki.artixlinux.org/Main/Troubleshooting#My_file_manager_.2F_application_cannot_perform_elevated_privileges_tasks
and a few times in the telegram group.

For cron in archlinux wiki
https://wiki.archlinux.org/title/Cron#Running_X.org_server-based_applications

And for what you have repeated (archwiki and suckless link):
Yes i have always done it like that, but it didnt work, so i tried sbus-lauch, which also did not work, thats why i said that it did not matter.

Re: Notification from Cronjobs not working

Reply #20
https://wiki.artixlinux.org/Main/Troubleshooting#My_file_manager_.2F_application_cannot_perform_elevated_privileges_tasks
Quote
Make sure your desktop session is started with dbus-launch in ~/.xinitrc
dwm is not a desktop session. It is a window manager.

Yes i have always done it like that, but it didnt work, so i tried sbus-lauch, which also did not work, thats why i said that it did not matter.
The logical conclusion would be to revert to exec, as it was proven to be unrelated to the problem.

Re: Notification from Cronjobs not working

Reply #21
From what I could see on my system, the variable DBUS_SESSION_BUS_ADDRESS is not set at all.

I'm using Autostart X at login that is, I don't use a Display Manager. When my system starts, I get a getty "Login:" prompt. From there on, I have this in my .profile (since now I'm using mksh:
Code: [Select]
if [ $(echo $0 | sed 's/^\(.\).*$/\1/g;1q') == "-" ]; then
unicode_start
pkill gpg
startx
fi
which starts X session for me. My .xinitrc then execs dwm. I'm using no Desktop Environment.

I am running 66 process supervision suite, and have the dbus service in the "default" tree, activated at startup.

It could be that the dbus service under 66 is configured differently than runit. I never used runit, so I don't know. What is the output of
Code: [Select]
$ ps aux | grep dbus
on your system? Are you using a DM?

I have:
Code: [Select]
root       741  0.0  0.0   2832  1028 ?        S    11:26   0:00 s6-supervise default-dbus
root       748  0.0  0.0   2832  1088 ?        S    11:26   0:00 s6-supervise default-dbus-log
s6log      861  0.0  0.0   2836  1020 ?        Ss   11:26   0:00 s6-log -d3 n3 T s1000000 /var/log/66/dbus
dbus       904  0.0  0.0   4672  3632 ?        Ss   11:26   0:00 dbus-daemon --system --nofork --nopidfile
strajder  1451  0.0  0.0   5280  1936 ?        S    11:26   0:00 dbus-launch --autolaunch=ad6e6c3f13375c49b5f732615fc877d6 --binary-syntax --close-stderr
strajder  1454  0.0  0.0   4184  2076 ?        Ss   11:26   0:00 /usr/bin/dbus-daemon --syslog-only --fork --print-pid 5 --print-address 7 --session
strajder  9214  0.0  0.0   9624  2308 pts/6    S+   19:11   0:00 grep dbus

Re: Notification from Cronjobs not working

Reply #22
Code: [Select]
$ ps aux | grep dbus
root      1326  0.0  0.0   2404  1128 ?        Ss   20:01   0:00 runsvdir -P /run/runit/service log: ctivating service name='org.freedesktop.RealtimeKit1' requested by ':1.8' (uid=1000 pid=1733 comm="pulseaudio --start --exit-idle-time=-1 ") (using servicehelper) dbus-daemon[1494]: [system] Successfully activated service 'org.freedesktop.RealtimeKit1' dbus-daemon[1494]: [system] Successfully activated service 'org.freedesktop.PolicyKit1' *** debug [daemon/old_main.c(159)]: selected 1 times .
root      1490  0.0  0.0   2252   724 ?        Ss   20:01   0:00 runsv dbus
dbus      1494  0.0  0.0   4476  3516 ?        S    20:01   0:00 dbus-daemon --system --nofork --nopidfile
nix       1615  0.0  0.0   4316  2396 ?        Ss   20:03   0:00 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --session
nix       1876  0.0  0.0   4184  2856 ?        S    20:04   0:00 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
nix       3436  0.0  0.0   8964  2384 pts/0    S+   20:19   0:00 grep --color=auto dbus

well, we're very similar, i also do not use a desktop enviroment, nor a display(login) manager. i autostart from my profile, here is my zprofile:
Code: [Select]
#!/bin/zsh

# profile file. Runs on login. Environmental variables are set here.

# If you don't plan on reverting to bash, you can remove the link in ~/.profile
# to clean up.

# Adds `~/.local/bin` to $PATH
export PATH="$PATH:${$(find ~/.local/bin -type d -printf %p:)%%:}"

unsetopt PROMPT_SP

# Default programs:
export EDITOR="nvim"
export TERMINAL="st"
export BROWSER="ff"
export READER="zathura"
export FILE="vu"

# ~/ Clean-up:
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_CACHE_HOME="$HOME/.cache"
export XINITRC="${XDG_CONFIG_HOME:-$HOME/.config}/x11/xinitrc"
export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority" # This line will break some DMs.
export NOTMUCH_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/notmuch-config"
export GTK2_RC_FILES="${XDG_CONFIG_HOME:-$HOME/.config}/gtk-2.0/gtkrc-2.0"
export LESSHISTFILE="-"
export WGETRC="${XDG_CONFIG_HOME:-$HOME/.config}/wget/wgetrc"
export INPUTRC="${XDG_CONFIG_HOME:-$HOME/.config}/shell/inputrc"
export ZDOTDIR="${XDG_CONFIG_HOME:-$HOME/.config}/zsh"
#export ALSA_CONFIG_PATH="$XDG_CONFIG_HOME/alsa/asoundrc"
export GNUPGHOME="${XDG_DATA_HOME:-$HOME/.local/share}/gnupg"
export WINEPREFIX="${XDG_DATA_HOME:-$HOME/.local/share}/wineprefixes/default"
export KODI_DATA="${XDG_DATA_HOME:-$HOME/.local/share}/kodi"
export PASSWORD_STORE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/password-store"
export TMUX_TMPDIR="$XDG_RUNTIME_DIR"
export ANDROID_SDK_HOME="${XDG_CONFIG_HOME:-$HOME/.config}/android"
export CARGO_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/cargo"
export GOPATH="${XDG_DATA_HOME:-$HOME/.local/share}/go"
export ANSIBLE_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/ansible/ansible.cfg"
export UNISON="${XDG_DATA_HOME:-$HOME/.local/share}/unison"
export HISTFILE="${XDG_DATA_HOME:-$HOME/.local/share}/history"
export WEECHAT_HOME="${XDG_CONFIG_HOME:-$HOME/.config}/weechat"
export MBSYNCRC="${XDG_CONFIG_HOME:-$HOME/.config}/mbsync/config"
export ELECTRUMDIR="${XDG_DATA_HOME:-$HOME/.local/share}/electrum"

# Other program settings:
export MANPAGER="nvim -c 'set ft=man'"
export DICS="/usr/share/stardict/dic/"
export SUDO_ASKPASS="$HOME/.local/bin/dmenupass"
export FZF_DEFAULT_OPTS="--layout=reverse --height 40%"
export LESS=-R
export LESS_TERMCAP_mb="$(printf '%b' '')"
export LESS_TERMCAP_md="$(printf '%b' '')"
export LESS_TERMCAP_me="$(printf '%b' '')"
export LESS_TERMCAP_so="$(printf '%b' '')"
export LESS_TERMCAP_se="$(printf '%b' '')"
export LESS_TERMCAP_us="$(printf '%b' '')"
export LESS_TERMCAP_ue="$(printf '%b' '')"
export LESSOPEN="| /usr/bin/highlight -O ansi %s 2>/dev/null"
export QT_QPA_PLATFORMTHEME="qt5ct" # Have QT use gtk2 theme.
export MOZ_USE_XINPUT2="1" # Mozilla smooth scrolling/touchpads.
export AWT_TOOLKIT="MToolkit wmname LG3D" #May have to install wmname
export _JAVA_AWT_WM_NONREPARENTING=1 # Fix for Java applications in dwm

# This is the list for lf icons:
. ${XDG_CONFIG_HOME:-$HOME/.config}/shell/lf-icons

export FONTPREVIEW_BG_COLOR="#282828"
export FONTPREVIEW_FG_COLOR="#ebdbb2"
export FONTPREVIEW_PREVIEW_TEXT="ilIrnmo0Oalbgq\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\nabcdefghijklm\nnopqrstuvwxyz\n1234567890~^*+-_\n!@#$%&()[]{}/|\\\\"
export PF_INFO="ascii title os host kernel uptime pkgs wm shell term res memory palette"
#setterm --bfreq=40 --blength=100

test ! -f ${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc && shortcuts >/dev/null 2>&1 &

if yay -Qs libxft-bgra >/dev/null 2>&1; then
# Start graphical server on user's current tty if not already running.
[ "$(tty)" = "/dev/tty1" ] && ! pidof -s Xorg >/dev/null 2>&1 && exec startx "$XINITRC"
else
echo "\033[31mIMPORTANT\033[0m: Note that \033[32m\`libxft-bgra\`\033[0m must be installed for this build of dwm.
Please run:
\033[32myay -S libxft-bgra-git\033[0m
and replace \`libxft\`. Afterwards, you may start the graphical server by running \`startx\`."
fi

# Switch escape and caps if tty and no passwd required:
sudo -n loadkeys ${XDG_DATA_HOME:-$HOME/.local/share}/larbs/ttymaps.kmap 2>/dev/null
though i only autostartx when im on tty1
i really dont know, maybe its cause of suite66...., though that should be irrelevant.

Re: Notification from Cronjobs not working

Reply #23
There are differences, the most obvious being the number of dbus-daemon processes and the lack of the one calling /usr/share/defaults/at-spi2/accessibility.conf on my side. runit ( @Artist ? ) and 66 ( @ndowens ) maintainers could perhaps take a look at this. (I'm happy with 66 state of things dbus-wise, but maybe runit could use some updates.)

Re: Notification from Cronjobs not working

Reply #24
# report
i have implemented https://forum.artixlinux.org/index.php/topic,2988.msg19413.html#msg19413 from @Artist
relevant (last 2lines) xinitrc :
Code: [Select]
echo 'export DBUS_SESSION_BUS_ADDRESS='$DBUS_SESSION_BUS_ADDRESS > /tmp/dsba ; chmod +x /tmp/dsba
exec dwm

crontab -l
Code: [Select]
* * * * * source /tmp/dsba; cronbat
1 10,14,18,22 * * * source /tmp/dsba; newsup
2 10,18 * * * source /tmp/dsba; checkup

in contrast to @strajder , i am not using the $DISPLAY variable at all, ony the dbus env var. idk what is happening, im happy that it works now, though i would like to know how.
@strajder  is using only the $DISPLAY env var, without the dbus env var. the opposite...??

Re: Notification from Cronjobs not working

Reply #25
For me using runit and only the DISPLAY variable this worked for quite a while until one day it stopped. Not sure if this was because of an update or a mnaual change. Later I switched to s6 where using only the DISPLAY variable also did not work. There seems not enough info yet to narrow the cause down to one single component.

Re: Notification from Cronjobs not working

Reply #26
An alternative way to show notification from a cronjob would be to write to a file from a cronjob, and have entr running on autostart ("cool autostart" in dwm), calling notify-send when the file changes.

Edit: Something like:
Code: [Select]
echo ~/notification | entr -cps 'xargs notify-send <~/notification'

Re: Notification from Cronjobs not working

Reply #27
In case '/run/user/1000/bus' is missing set 'unix:runtime=yes' in /etc/dbus-1/session-local.conf

Quote from: /etc/dbus-1/session-local.conf
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
        <listen>unix:runtime=yes</listen>
</busconfig>


bonus edit:
cron or whoever should then be able to connect to dbus w/o explicitly passing $DBUS_SESSION_BUS_ADDRESS


read here: https://dbus.freedesktop.org/doc/dbus-specification.html