This https://wiki.archlinux.org/title/Cron#Running_X.org_server-based_applications says that,
to have notifications from a cronjob, you have to specify `DBUS_SESSION_BUS_ADDRESS` and `DISPLAY` variables.
The `DISPLAY` variable is easy, it is
allways ':0'
But the problem is `DBUS_SESSION_BUS_ADDRESS`. Doing this in a terminal:
$ echo $DBUS_SESSION_BUS_ADDRESS
unix:abstract=/tmp/dbus-TmOWK21wNR,guid=1770ea5d0622fa8ebc76a544612cc0ad
the variable is different every login, so i cant specify it in the crontab.
Now, https://wiki.archlinux.org/title/Cron#Running_X.org_server-based_applications says that dbus var should be like this:
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $USER)/bus
but in Artix it will be this:
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $USER)/bus-1
but this doesnt work, because it is not true, because like i said doing this in a terminal:
$ echo $DBUS_SESSION_BUS_ADDRESS
unix:abstract=/tmp/dbus-TmOWK21wNR,guid=1770ea5d0622fa8ebc76a544612cc0ad
tells you the real value.
so to have it always the same, i wrote this in my
zprofile:
export DBUS_SESSION_BUS_ADDRESS='unix:path=/run/user/1000/bus-1'
But, that breaks dunst = doesn't run
# Temporary fix:
writing this in my
`zprofie`:
export DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-TmOWK21wNR,guid=1770ea5d0622fa8ebc76a544612cc0ad"
and then having this in my crontab
* * * * * export DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-TmOWK21wNR,guid=1770ea5d0622fa8ebc76a544612cc0ad"; export DISPLAY=':0'; notify-send "beep bop"
...then it works,
BUT like i said earlier, every login the dbus variable will change, so the crontab will not have the real vaule.
and just donig only this:
* * * * * export DISPLAY=':0'; notify-send "beep bop"
does not work.
What X program do you need to run with cron?
Conceptually, cron is meant for programs which don't interact with the user and are highly automated (for example, mail check). X programs don't fit that purpose.
If you want to notify the user from a cronjob, you can do something like:
/usr/bin/env DISPLAY=:0 /usr/bin/notify-send -i $ICON "$TITLE" "$MESSAGE"
This is a line from my mail checking script, which I have in my crontab.
accidentaly i pressed post instead of preview, sorry.
@strajder please read my OriginalPost again, cause i have allot of other info.
additional info
first my zprofile runs, then my xprofile, and then my xinitrc (well first xinit but first it sources xprofile before running itself)
XINITRC:
# export STATUSBAR="i3blocks" # Uncomment this line when using i3.
if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/x11/xprofile" ]; then
. "${XDG_CONFIG_HOME:-$HOME/.config}/x11/xprofile"
else
. "$HOME/.xprofile"
fi
# ssh-agent dwm
# ssh-agent i3
eval $(dbus-launch --sh-syntax --exit-with-session)
dbus-launch --exit-with-session dwm
XPROFILE:
#!/bin/sh
# Fix Gnome Apps Slow Start due to failing services
# Add this when you include flatpak in your system
# dbus-update-activation-environment --systemd DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY
#xrdb ${XDG_CONFIG_HOME:-$HOME/.config}/x11/xresources & # Uncomment to use Xresources colors/settings on startup
lxpolkit & # ask you for root pw
remaps & # run the remaps script, switching caps/esc and more; check it for more info
xcompmgr & # xcompmgr for transparency
dunst & # dunst for notifications
xset r rate 300 50 & # Speed xrate up
unclutter & # Remove mouse when idle
{ mpd && sb-music ;} & # music player
{ fuego-only ; setbg ;} & # resolution and background
light -N 10 & light -S 100 &
redshift -l 42.66:21.16 -t 6500:3000 >/dev/null 2>&1 &
mpv --no-audio-display --volume=50 "$XDG_DATA_HOME"/win_XP_Startup.mp3 >/dev/null 2>&1 &
/usr/lib/kdeconnectd & #KDE-Connect app for phones
#xset b 50 21 120 #nice beep
# This line autostarts an instance of Pulseaudio that does not exit on idle.
# This is "necessary" on Artix due to a current bug between PA and
# Chromium-based browsers where they fail to start PA and use dummy output.
pidof -s runit &&
! pidof -s pulseaudio >/dev/null 2>&1 &&
setsid -f pulseaudio --start --exit-idle-time=-1 >/dev/null 2>&1
# vim: ts=8 sw=8
From
man 5 crontab:
Note "a command", not "multiple commands".
Next, it is best to use /usr/bin/env instead of export, in order not to pollute the environment of subsequent commands.
Also see: https://askubuntu.com/a/205698
@strajder but i am using only one command (notify-send "beep bop"), what do you mean?
so should my crontab look like this:
* * * * * /usr/bin/env DISPLAY=:0 /usr/bin/notify-send "beep bop"
because i have tried that and it did not work.
This command works for me. It sends a notification every minute.
Can you post your
/var/log/crond.log (use paste.artixlinux.org)?
Really? it has never worked for me. Even in arch, i always had to write it with the dbus env var also.
here is the log: https://paste.artixlinux.org/view/raw/c60a9015
Do you have an X session running when testing? This requires a running X session (on :0).
What happens when you do
$ notify-send Test
from a terminal emulator under X?
Edit: Also make sure you have both
dbus and
dbus-<your_init> installed and the dbus service setup and running for your init. I use 66, so I have
dbus-suite66 installed. You should also probably ditch that dbus-launch line.
Edit 2: This is my .xinitrc (https://git.sr.ht/~strahinja/dotfiles/tree/master/item/.xinitrc). I use dwm. It needs to end with an
exec line.
yes of course, i am using dwm
i installed artix lxde runit
so it has cronie installed and enabled by default
Install dbus-runit package and setup the dbus service under runit.
@strajder sorry but i dont understand you. i said that i have it installed, and enabled.
but anyhow, i re-did it
sudo pacman -S dbus-runit
sudo ln -sf /etc/runit/sv/cronie /run/runit/service/
sudo sv restart cronie
still not successful.
And my other questions?
@strajder bruh which?
the x session one?
well yes, i am running dwm, so yes when i run, in my terminal `notify-send Test` it works. i have mentioned this in my OP.
and if you mean, your xinit, which i just now saw, yes i know that. but 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`.
doesnt make a diff though anyhow.
Link?
https://wiki.archlinux.org/title/Xinit#xinitrc
https://dwm.suckless.org/tutorial/
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:
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
This doesn't explain how the line:
* * * * * /usr/bin/env DISPLAY=:0 /usr/bin/notify-send "beep bop"
works on my system, but not for the OP. I don't have any complicated setup with
DBUS_SESSION_BUS_ADDRESS.
@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.
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:
$ 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
Where in the Artix wiki? Provide a link.
I repeat:
https://wiki.archlinux.org/title/Xinit#xinitrc
https://dwm.suckless.org/tutorial/
@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.
https://wiki.artixlinux.org/Main/Troubleshooting#My_file_manager_.2F_application_cannot_perform_elevated_privileges_tasks
dwm is not a desktop session. It is a window manager.
The logical conclusion would be to revert to exec, as it was proven to be unrelated to the problem.
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 (https://wiki.archlinux.org/title/Xinit#Autostart_X_at_login) that is, I don't use a Display Manager (https://wiki.archlinux.org/title/Display_manager). When my system starts, I get a getty "Login:" prompt. From there on, I have this in my .profile (https://git.sr.ht/~strahinja/dotfiles/tree/master/item/profile.d/profile) (since now I'm using mksh (https://www.mirbsd.org/mksh.htm):
if [ $(echo $0 | sed 's/^\(.\).*$/\1/g;1q') == "-" ]; then
unicode_start
pkill gpg
startx
fi
which starts X session for me. My .xinitrc (https://git.sr.ht/~strahinja/dotfiles/tree/master/item/.xinitrc) then
execs dwm. I'm using
no Desktop Environment (https://wiki.archlinux.org/title/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
$ ps aux | grep dbus
on your system? Are you using a DM?
I have:
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
$ 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:
#!/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' '[1;31m')"
export LESS_TERMCAP_md="$(printf '%b' '[1;36m')"
export LESS_TERMCAP_me="$(printf '%b' '[0m')"
export LESS_TERMCAP_so="$(printf '%b' '[01;44;33m')"
export LESS_TERMCAP_se="$(printf '%b' '[0m')"
export LESS_TERMCAP_us="$(printf '%b' '[1;32m')"
export LESS_TERMCAP_ue="$(printf '%b' '[0m')"
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.
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.)
# report
i have implemented https://forum.artixlinux.org/index.php/topic,2988.msg19413.html#msg19413 from
@Artist relevant (last 2lines) xinitrc :
echo 'export DBUS_SESSION_BUS_ADDRESS='$DBUS_SESSION_BUS_ADDRESS > /tmp/dsba ; chmod +x /tmp/dsba
exec dwm
crontab -l
* * * * * 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...??
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.
An alternative way to show notification from a cronjob would be to write to a file from a cronjob, and have entr (http://eradman.com/entrproject) running on autostart ("cool autostart (https://dwm.suckless.org/patches/cool_autostart/)" in dwm), calling notify-send when the file changes.
Edit: Something like:
echo ~/notification | entr -cps 'xargs notify-send <~/notification'
In case '/run/user/1000/bus' is missing set 'unix:runtime=yes' in /etc/dbus-1/session-local.conf
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