Registered Member
|
Hello,
I have a problem about using kdialog in bash script then running it with crontab. It worked well before I do a user configuration files restoration from backup. And the script file itself works well even now: it generates a well behavioured notification at the bottom right corner with system notification style if the script is executed through Konsole using bash or sh command. It's only not behaviouring as expected when running by crontab. [I really am sorry that I forgot to mention this. Added @ 15:53 29/11/2016 UTC] I followed the instruction in this page on KDE TechBase. And I have added,
to make it show passive message box in the right display. And it worked very well, i.e. showing correct message box at the bottom right corner with system dialogue. But a few days ago, I do a full restoration of my user configuration files (the files lie in $HOME and are in hidden state or under hidden directories) from backup. After this, the same bash script run through crontab won't show the passive message box in the correct way. It just show the message in the centre of my screen with a rectangular box in system theme style ( a grey box under Breeze Dark theme). But this same script works well in a fresh installed system running in a virtual machine when called from crontab. So I guess the problem is not with my usage of kdialog but caused by something else pertaining to settings of display, sessions or something else. But I cannot identify it. Could anyone give some suggestions on how to make it right? TIA, CnZhx
Last edited by CnZhx on Tue Nov 29, 2016 3:53 pm, edited 1 time in total.
|
Registered Member
|
Maybe you don't have the notification applet in the system tray?
Right-click on the small up-arrow that shows the hidden icons and choose "System Tray Settings". You should be able to enable/disable it there (General->Additional Entries). If it is enabled, check its settings. Left-click on the up-arrow to show the hidden icons, right-click on the notifications applet icon and choose "Notifications Settings". Make sure that the option "Show application and system notifications" is turned on. |
Registered Member
|
Thank you wolfi323 And I am very sorry that I forgot to mention that if I run the script in Konsole, then the notification is in a correct manner. It's only not behaviour as expected when running by crontab. I'll edit OP and add this information. |
Registered Member
|
After such a long time, I could not find the reason causing the notification being shown at the centre of the screen. I set up a virtual system with the same configuration as my desktop using VirtualBox, tried to overwrite the use configuration files from those in my desktop system, but could not recur the same symptom as on my desktop. I even tried to reinstall my desktop then copy old configuration files group by group but I still could not isolate the one(s) caused the problem.
While searching on the web, I found that people suggested to use `notify-send` to send notification to the desktop and it has a better cross desktop environment compatibility than DE native app. So I tried following command,
Just like kdialog, this command works in shell but not in crontab. Then I started searching a method to let me send notification to desktop. I found in several posts (e.g. post 1, post 2) indicating a dbus session path env might be required to export before the actual notification to send. So I did this for a cron job and it worked finally,
But this is not a good implementation because the actual path of dbus session changes every time a system reboot or resume. Now I see this is not a problem related to kdialog, but a problem with my system environment settings. The problem is, the cronjob worked very well without the need to set DBUS_SESSION_BUS_ADDRESS before something changed in my system, to be specific, only those settings related to my user. But now it requires. Why? And how to make it acts as before? I am not an experienced user of Linux, so I think this is the best that I can find out. Could anyone give me any suggestion on how to make this cron job run as before without setting the DBUS_SESSION_BUS_ADDRESS? Many thanks in advance. CnZhx |
Registered Member
|
I finally found following implementation to export the dbus session path automatically from here.
This snippet is added right before `export DISPLAY=:0`. But I still cannot figure out the reason that why the dbus session path given by Konsole (`env | grep DBUS_SESSION_BUS_ADDRESS`) is different from that in the file of `$HOME/.dbus/session-bus/<machine-id>-0`. I'll mark this problem solved but an explanation for the root reason is still welcomed. CnZhx |
Registered Member
|
I just want to report that this problem has gone at least from now on (tested on KDE Plasma 5.9.0 and KDE Frameworks 5.30.0, or before the release of them. |
Registered Member
|
I just want to report that things changed for the passed time.
Workaround in upper post worked for a while, but it didn't work for a long time. I have tried to change the way to set `DBUS_SESSION_BUS_ADDRESS` according to what I could find through Google but in no vain. The best result I can get is to display the notification box ugly at the top left corner of the screen. But surprisingly, I just find out that `notify-send` now works well without the need to set `DBUS_SESSION_BUS_ADDRESS` in the script called by cron. For a reference, now, I am on following environment,
I am quite confused by `kdialog` although it seems very powerful and versatile based on the help information. |
Registered Member
|
Apparently, this is because cron jobs do not run in any sort of display environment, and they are not meant to involve any GUI or TUI apps.
However, a crontab entry like the following seems to work:
|
Registered Member
|
Hi @sadi , thank you very much for this elegant solution
|
Registered users: Bing [Bot], Google [Bot], kesang, Yahoo [Bot]