LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 06-29-2019, 07:41 PM   #1
ewlabonte
Member
 
Registered: Mar 2005
Distribution: Debian Stretch
Posts: 127

Rep: Reputation: 15
Problem with crontab in Mate


I'm using Debian Stretch. I have a crontab entry which I have used in numerable linux distributions with no problems, but for some reason it doesn't work in Debian Stretch with the mate desktop. I also use the window manager pekwm, and the entry works fine. But not in mate. What makes it more problematic, the same entry works fine with mate in other distros, like Devuan and Slackware. Here's the entry:

*/7 * * * * DISPLAY=:0 /home/ewl/bin/testwm

testwm is a script which tests what window manager or desktop environment is running and uses the appropriate command for that wm to change the wallpaper. Here's the script:

#!/bin/bash
x=`ps -e | grep mate-session`
y=`ps -e | grep pekwm`
z=`ps -e | grep dwm`
if [[ -n $x ]]
then /home/ewl/bin/materia
elif [[ -n $y ]]
then /home/ewl/bin/randfeh
elif [[ -n $z ]]
then xsetroot -solid black
fi


materia is a script that changes the desktop in mate and randfeh changes the wallpaper in wm's that use feh to display wallpaper. When I run testwm and materia by themselves in a terminal in mate, the scripts work fine. But it won't run in crontab, under mate. But it does run in crontab in pekwm.
 
Old 06-29-2019, 08:17 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,364
Blog Entries: 28

Rep: Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150
What does /var/log/cron have to say about it?
 
Old 06-30-2019, 05:20 PM   #3
ewlabonte
Member
 
Registered: Mar 2005
Distribution: Debian Stretch
Posts: 127

Original Poster
Rep: Reputation: 15
I have no /var/log/cron
 
Old 06-30-2019, 05:27 PM   #4
ewlabonte
Member
 
Registered: Mar 2005
Distribution: Debian Stretch
Posts: 127

Original Poster
Rep: Reputation: 15
Here's all references to CRON in /var/log/syslog:

Jun 30 15:42:01 porter CRON[8710]: (ewl) CMD (DISPLAY=:0^I/home/ewl/bin/testwm)
Jun 30 15:49:01 porter CRON[8859]: (ewl) CMD (DISPLAY=:0^I/home/ewl/bin/testwm)
Jun 30 18:17:52 porter cron[377]: (CRON) INFO (pidfile fd = 3)
Jun 30 18:17:52 porter cron[377]: (CRON) INFO (Running @reboot jobs)
Jun 30 18:21:01 porter CRON[1312]: (ewl) CMD (DISPLAY=:0^I/home/ewl/bin/testwm)
 
Old 06-30-2019, 05:29 PM   #5
ewlabonte
Member
 
Registered: Mar 2005
Distribution: Debian Stretch
Posts: 127

Original Poster
Rep: Reputation: 15
And here's all references to cron, lower case:

Jun 30 15:35:51 porter anacron[411]: Job `cron.daily' terminated
Jun 30 15:35:51 porter anacron[411]: Normal exit (1 job run)
Jun 30 15:35:51 porter systemd[1]: anacron.timer: Adding 3min 40.093320s random time.
Jun 30 15:53:25 porter systemd[1]: Stopped Trigger anacron every hour.
Jun 30 18:17:52 porter cron[377]: (CRON) INFO (pidfile fd = 3)
Jun 30 18:17:52 porter cron[377]: (CRON) INFO (Running @reboot jobs)
Jun 30 18:17:52 porter systemd[1]: anacron.timer: Adding 1min 46.073334s random time.
Jun 30 18:17:52 porter systemd[1]: Started Trigger anacron every hour.
Jun 30 18:17:52 porter systemd[1]: Started Run anacron jobs.
Jun 30 18:17:52 porter systemd[1]: anacron.timer: Adding 40.482244s random time.
Jun 30 18:17:52 porter systemd[1]: anacron.timer: Adding 3min 1.838896s random time.
Jun 30 18:17:52 porter anacron[398]: Anacron 2.3 started on 2019-06-30
Jun 30 18:17:52 porter anacron[398]: Normal exit (0 jobs run)
Jun 30 18:17:52 porter systemd[1]: anacron.timer: Adding 3min 6.490945s random time.
Jun 30 18:18:21 porter systemd[1]: anacron.timer: Adding 27.553187s random time.
 
Old 06-30-2019, 08:57 PM   #6
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,364
Blog Entries: 28

Rep: Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150
Quote:
I have no /var/log/cron
Drat. I have one on Slackware, but I don't have one on the Ubuntu MATE box over there---->.

Nice job hunting down those other references. Nothing in them looks like what I saw in /var/log/cron for the cronjob I recently misconfigured.

I must admit that I'm puzzled as to how a GUI environment could affect a cron job.

Would it be possibel to see the relevant line for that cronjob?
 
Old 07-01-2019, 09:44 AM   #7
ewlabonte
Member
 
Registered: Mar 2005
Distribution: Debian Stretch
Posts: 127

Original Poster
Rep: Reputation: 15
I've only got one cronjob with my userid. This is crontab -l

#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
*/7 * * * * DISPLAY=:0 /home/ewl/bin/testwm
 
Old 07-01-2019, 10:26 AM   #8
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,153

Rep: Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265
Quote:
Originally Posted by ewlabonte View Post
if [[ -n $x ]]
Failing to quote the variable with -n is a common mistake. This test always returns true,
 
Old 07-01-2019, 05:09 PM   #9
ewlabonte
Member
 
Registered: Mar 2005
Distribution: Debian Stretch
Posts: 127

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by smallpond View Post
Failing to quote the variable with -n is a common mistake. This test always returns true,
But the failure of the script isn't the problem. It works when I call it by itself. It just doesn't work when I call it in a cronjob... in mate... in debian. It works in pekwm in crontab, and it works in crontab and mate when I'm running the same scripts and cronjob in slackware and devuan. So I don't think that's the problem. I did change it and it didn't fix it.
 
Old 07-01-2019, 09:07 PM   #10
ewlabonte
Member
 
Registered: Mar 2005
Distribution: Debian Stretch
Posts: 127

Original Poster
Rep: Reputation: 15
I've kind of given up on this and have installed "variety" to handle changing wallpaper. I thought a cron job would be simpler, but apparently there's a problem.
 
Old 07-01-2019, 09:42 PM   #11
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,364
Blog Entries: 28

Rep: Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150Reputation: 6150
This is a complete shot in the dark, but you might try turning

Code:
DISPLAY=:0 /home/ewl/bin/testwm
into a script and calling that script from cron.

Also, if you have a script that changes the background in MATE, I'd love to see it. I have a little script that uses fbsetbg in Fluxbox, and I set up slideshow in KDE, but MATE doesn't offer a "slideshow" option.
 
Old 07-02-2019, 10:12 AM   #12
ewlabonte
Member
 
Registered: Mar 2005
Distribution: Debian Stretch
Posts: 127

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by frankbell View Post
This is a complete shot in the dark, but you might try turning

Code:
DISPLAY=:0 /home/ewl/bin/testwm
into a script and calling that script from cron.

Also, if you have a script that changes the background in MATE, I'd love to see it. I have a little script that uses fbsetbg in Fluxbox, and I set up slideshow in KDE, but MATE doesn't offer a "slideshow" option.
For the script I had to put DISPLAY=:0 and /home/ewl/bin/testwm on different lines. But after creating that script and calling it in cron, it didn't solve the problem.

The script to change mate's wallpaper I call "materia" for no particular reason. It has "mate" in it. But here it is. My wallpapers are in /home/ewl/Pictures/Wallpapers/ :

#!/bin/sh
# Script to randomly set Background from files in a directory

# Directory Containing Pictures
DIR="/home/ewl/Pictures/Wallpapers"

# Command to Select a random jpg file from directory
# Delete the *.jpg to select any file but it may return a folder
PIC=$(ls $DIR/* | shuf -n1)

# Command to set Background Image
gsettings set org.mate.background picture-filename $PIC
 
Old 07-03-2019, 10:49 PM   #13
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

/var/log/syslog seems to indicate that the script is being called.
To find out why it is not doing what you expect I suggest you add some debugging to the script. Eg something like:
Code:
#!/bin/bash
LG=/home/ewl/testwm.log
date >> $LG
echo "DISPLAY is $DISPLAY" >> $LG
x=`ps -e | grep mate-session`
y=`ps -e | grep pekwm`
z=`ps -e | grep dwm`
echo "x is $x" >> $LG
echo "y is $y" >> $LG
echo "z is $z" >> $LG

if [[ -n $x ]] ; then
  /home/ewl/bin/materia >> $LG 2>&1
  echo "Called /home/ewl/bin/materia" >> $LG
elif [[ -n $y ]] ; then
  /home/ewl/bin/randfeh >> $LG 2>&1
  echo "Called /home/ewl/bin/randfeh" >> $LG
elif [[ -n $z ]] ; then
  xsetroot -solid black  >> $LG 2>&1
  echo "Called xsetroot" >> $LG
fi
echo "Done!" >> $LG
HTH,

Evo2.

Last edited by evo2; 07-03-2019 at 10:56 PM.
 
1 members found this post helpful.
Old 07-04-2019, 08:52 AM   #14
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,988

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
Quote:
But the failure of the script isn't the problem. It works when I call it by itself. It just doesn't work when I call it in a cronjob... in mate... in debian. It works in pekwm in crontab, and it works in crontab and mate when I'm running the same scripts and cronjob in slackware and devuan. So I don't think that's the problem. I did change it and it didn't fix it.
Whenever I've run into this kind of problem, i.e. a script runs OK for the user but fails when called as a cron job, it invariably turned out to be due to the cron environment and the user environment having PATH differences. It's usually fixed by rewriting the script to have full absolute paths to all called locations and executables.
 
Old 07-04-2019, 10:25 AM   #15
ewlabonte
Member
 
Registered: Mar 2005
Distribution: Debian Stretch
Posts: 127

Original Poster
Rep: Reputation: 15
Cool

Quote:
Originally Posted by evo2 View Post
Hi,

/var/log/syslog seems to indicate that the script is being called.
To find out why it is not doing what you expect I suggest you add some debugging to the script. Eg something like:
Code:
#!/bin/bash
LG=/home/ewl/testwm.log
date >> $LG
echo "DISPLAY is $DISPLAY" >> $LG
x=`ps -e | grep mate-session`
y=`ps -e | grep pekwm`
z=`ps -e | grep dwm`
echo "x is $x" >> $LG
echo "y is $y" >> $LG
echo "z is $z" >> $LG

if [[ -n $x ]] ; then
  /home/ewl/bin/materia >> $LG 2>&1
  echo "Called /home/ewl/bin/materia" >> $LG
elif [[ -n $y ]] ; then
  /home/ewl/bin/randfeh >> $LG 2>&1
  echo "Called /home/ewl/bin/randfeh" >> $LG
elif [[ -n $z ]] ; then
  xsetroot -solid black  >> $LG 2>&1
  echo "Called xsetroot" >> $LG
fi
echo "Done!" >> $LG
Excellent idea. Crontab apparently called testwm which called materia, but I got no response on the desktop. If I call materia manually, it does change the wallpaper. But it didn't do that through crontab. Here's testwm.log:

Thu Jul 4 11:21:01 EDT 2019
DISPLAY is :0
x is 9667 ? 00:00:00 mate-session
y is
z is
Called /home/ewl/bin/materia
Done!

Last edited by ewlabonte; 07-04-2019 at 10:28 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Ubuntu MATE 15.04 Arrives With MATE Desktop 1.8.2 and MATE Tweak LXer Syndicated Linux News 0 05-15-2015 09:30 AM
[SOLVED] anyone else having update problems with Mint15 Mate & 16 Cinnamon or mate RC 1sweetwater! Linux Mint 2 08-05-2014 06:42 PM
[SOLVED] Mate switched to cinnamon wthout permission mint-13-mate littlejoe5 Linux Mint 7 05-08-2014 10:54 PM
[SOLVED] Problem with crontab:: command not executed properly via crontab Ankush Seth Linux - Newbie 11 11-11-2013 06:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 10:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration