On 17/10/16 18:30, Yamaban wrote:
On Mon, 17 Oct 2016 17:33, Bob Williams wrote:
I have a bash script to generate the sig featured below.
#!/bin/bash
# script to generate a topical linux mailsig
SIGFILE=/home/bob/Documents/Signatures/daily.sig
: > $SIGFILE # (re)creates an empty SIGFILE
echo "Bob Williams" >> $SIGFILE echo " System: " `uname -sr` >> $SIGFILE distro=" $(head -n 1 /etc/SuSE-release)"
May or may not work:
kde=`kf5-config -v | grep KDE` Qt=`kf5-config -v | grep Qt`
And here comes the blopper, that will not work for sure:
plasma=`kcmshell5 -v | awk '{print $2}'`
echo " Distro: $distro" >> $SIGFILE echo " Desktop: $kde, $Qt and Plasma: $plasma" >> $SIGFILE exit 0
When run from my user command line it works correctly, but when I run it from my crontab, it fails to get the plasma version. So the last line of output reads:
Desktop: KDE Frameworks: 5.26.0, Qt: 5.6.1 and Plasma:
The error message returned by the system is:
QXcbConnection: Could not connect to display
I'm guessing that cron is not running in graphical environment, but not sure why that would make a difference.
Can anyone suggest a solution/workaround, please?
TL;DR: Missing DISPLAY variable in enviornment from cron.
What happens in detail: - a script from cron runs in a minimal environment. - only very few environment variables are defined at all.
The command "kf5-config" wants / partially needs a working "DISPLAY".
The command "kcmshell5" needs a set "DISPLAY" variable or it fails.
Try with a extra line before / after the SIGFILE=.... line: [code] export DISPLAY=:0.0 [/code]
Other variables may be needed also.
try to start your script from an other script via a line: #/usr/bin/bash exec -c <your-sig-script>
to simulate a empty environment. also see "help exec" for details on the "-c" option.
- Yamaban.
Many thanks for the explanation re unavailable environment variables, and lots of suggestions to try. -- Bob Williams System: Linux 4.4.22-1-default Distro: openSUSE 42.2 Beta (x86_64) Desktop: KDE Frameworks: 5.26.0, Qt: 5.6.1 and Plasma: 5.8.0