crontab ???

Created this file called ‘wallpaperchanger’ using crontab -e

* * * * * /home/USER/bin/wallpaperchanger > /home/USER/Documents/cron.log 

the script ‘wallpaperchanger’ reads thus:

DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-uri file://"$(find /run/media/USER/Wallpaper -type f | shuf -n1)"

which executes fine when run manually through the GUI

However … when be run via CRON all i get is an empty ‘cron.log’ file and the script is not executed … the system then sends me the following e-mail message!!

*** (process:9579): WARNING **: Command line `dbus-launch --autolaunch=aaf45848b77796875f161bed0000071b --binary-syntax --close-stderr’ exited with non-zero exit status 1: No protocol specified
Autolaunch error: X11 initialization failed.

What can be wrong??

Brand new installation of OpenSuSe 12.2 32bit … GNOME Shell 3.4.2

I don’t know about gsettings, but I have seen such a problem with trying to run a GUI application using sudo in terminal instead of using kdesu (or gnomesu) for instance. As cron, perhaps it is being run as root in terminal is the problem?

Thank You,

With systemd, cron jobs are invoked by a systemd unit, not as a BASH job.

I haven’t looked deeply into this yet, but here is some starting info
Although my notes say there should be a Unit called “timer.service” it doesn’t exist on my 12.3, a search turns up a “cron.service” The following should tell you the location of the Unit config file

systemctl status cron.service

View the contents of the config file

cat /usr/lib/systemd/system/cron.service

You can edit that file directly (not recommended) or copy that file to /etc/systemd/system/ and then modify the copy which will take priority over the default (original)

cp /usr/lib/systemd/system/cron.service /etc/systemd/system/

You’ll notice that cron.service calls a Unit so you’d probably have to configure your cron job as a custom Unit as well. Whatever your job is, script, binary, task, app or anything else can be called by your Unit.

I haven’t reviewed how to set the timing, hopefully that should be in the MAN pages or someone might have written a short tutorial.

Hope to have at least pointed you in the right direction,
TSU

On 2013-04-07 07:26, tsu2 wrote:
> With systemd, cron jobs are invoked by a systemd unit, not as a BASH
> job.
>
> I haven’t looked deeply into this yet, but here is some starting info
> Although my notes say there should be a Unit called “timer.service” it
> doesn’t exist on my 12.3, a search turns up a “cron.service” The
> following should tell you the location of the Unit config file

Notice that the cron job is running, because he gets an email with the
error produced by the job.

An email is the standard way that cron communicates errors from the job
it runs.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

On 2013-04-07 04:46, griadooss wrote:
> Created this file called ‘wallpaperchanger’ using crontab -e

which user does the “crontab -e”?


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

In any case, your posting of your script is not realy interpretable. You should do a

ls -l /home/USER/bin/wallpaperchanger 

and

cat /home/USER/bin/wallpaperchanger

and copy/paste that direct from the terminal in between the CODE tags. Now all new lines seem to be gone, thus nobody can see if those are syntacticaly correct statements.

As it does not start with a “shebang” it is not a script. At the most it is a bunch of statements.

thanks … a wee bit over my head … but here is what i have found ::

output to “systemctl status cron.service” produces:

systemctl status cron.service
cron.service - Command Scheduler
Loaded: loaded (/lib/systemd/system/cron.service; enabled)
Active: active (running) since Fri, 12 Apr 2013 17:07:22 +1000; 2h 34min ago
Main PID: 1154 (cron)
CGroup: name=systemd:/system/cron.service
└ 1154 /usr/sbin/cron -n

Apr 12 17:07:22 wsos01 /usr/sbin/cron[1154]: (CRON) INFO (running with inotify support)
Apr 12 19:37:01 wsos01 /usr/sbin/cron[1154]: (griadooss) RELOAD (/var/spool/cron/tabs/griadooss)

output to "cat /usr/lib/systemd/system/cron.service" produces error as no such directory:

wsos01:/usr/lib/systemd # ls -l
total 4
drwxr-xr-x 2 root root 4096 Apr 4 13:15 user

and under “/usr/lib/systemd/user” appears:

wsos01:/usr/lib/systemd/user # ls -l
total 12
lrwxrwxrwx 1 root root 36 Apr 4 13:15 bluetooth.target -> /lib/systemd/system/bluetooth.target
-rw-r–r-- 1 root root 348 Jan 4 22:52 default.target
-rw-r–r-- 1 root root 496 Jan 4 22:52 exit.service
-rw-r–r-- 1 root root 475 Jan 4 22:52 exit.target
lrwxrwxrwx 1 root root 34 Apr 4 13:15 printer.target -> /lib/systemd/system/printer.target
lrwxrwxrwx 1 root root 35 Apr 4 13:15 shutdown.target -> /lib/systemd/system/shutdown.target
lrwxrwxrwx 1 root root 34 Apr 4 13:15 sockets.target -> /lib/systemd/system/sockets.target
lrwxrwxrwx 1 root root 32 Apr 4 13:15 sound.target -> /lib/systemd/system/sound.target

… this is where i slip below the surface :frowning:

just a standard user … i am not logged on as ‘root’ … I read somewhere that this is ‘best practice’ rather than using ‘root’ and making system wide job for this??

Okay … good point … so here are the outputs

griadooss@wsos01:~> ls -l /home/griadooss/bin/wallpaperchanger.sh
-rwxr-xr-x 1 griadooss users 190 Apr 12 19:20 /home/griadooss/bin/wallpaperchanger.sh

and

griadooss@wsos01:~> cat /home/griadooss/bin/wallpaperchanger.sh
#!/bin/bash

DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-uri file://"$(find /run/media/griadooss/SG1000/Wallpaper/WallpaperHD -type f | shuf -n1)"

griadooss@wsos01:~> 

and the mail i am getting reads:

From [EMAIL="griadooss@linux-9ar1.site"]griadooss@linux-9ar1.site[/EMAIL]  Fri Apr 12 20:10:02 2013
Return-Path: <griadooss@linux-9ar1.site>
X-Original-To: griadooss
Delivered-To: [EMAIL="griadooss@linux-9ar1.site"]griadooss@linux-9ar1.site[/EMAIL]
Received: by linux-9ar1.site (Postfix, from userid 1000)
    id 0E30EDF706; Fri, 12 Apr 2013 20:10:02 +1000 (EST)
From: [EMAIL="griadooss@linux-9ar1.site"]griadooss@linux-9ar1.site[/EMAIL] (Cron Daemon)
To: [EMAIL="griadooss@linux-9ar1.site"]griadooss@linux-9ar1.site[/EMAIL]
Subject: Cron <griadooss@wsos01> /home/griadooss/bin/wallpaperchanger.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/griadooss>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=griadooss>
X-Cron-Env: <USER=griadooss>
Message-Id: <20130412101002.0E30EDF706@linux-9ar1.site>
Date: Fri, 12 Apr 2013 20:10:02 +1000 (EST)

** (process:6856): WARNING **: Command line `dbus-launch --autolaunch=aaf45848b77796875f161bed0000071b --binary-syntax --close-stderr' exited with non-zero exit status 1: No protocol specified
Autolaunch error: X11 initialization failed.


** (process:6856): WARNING **: Command line `dbus-launch --autolaunch=aaf45848b77796875f161bed0000071b --binary-syntax --close-stderr' exited with non-zero exit status 1: No protocol specified
Autolaunch error: X11 initialization failed.



and the cron job

griadooss@wsos01:~> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.e1WsHc installed on Fri Apr 12 19:36:30 2013)
# (Cronie version 4.2)
*/1 * * * * /home/griadooss/bin/wallpaperchanger.sh

… it must be something simple that i am doing wrong!!

Thank you for your help

While I am not fluent at all with that program gsettings, I conclude from your call to it where you add a DISPLAY setting to it, that it is bound to do something on a running Xserver display. From your crontab there is not such a thing. Does look logical when you consider the possibilties like:
. it could be that there is nobody loged in at all;
. or another user then griadooss is loged in at DISPAY 0
. or more combinations.

And even when at the moment cron starts the run, griadooss is loged in at DISPLAY 0, normaly it is not allowed to do things from “outside” on that display without the session owner allowing this (when not, everybody on the internet could do things in your session, only firewalls would prevent this).

This explain why it works as intenede by you when run from within a session and why it does not function as intened by you (but it works as intended by the designers of X) when run from your crontab.

BTW your question about using your user crontab or root’s crontab. Of course when it is a user action, the user should use his own crontab. Using root’s crontab would open a huge can of worms.

Okay … thanks for the help Hank … unfort I am no ‘admin’ … just a run-of-the-mill ex Windows user. I admit that I also am ‘not fluent’ with ‘gsettings’ … have gleaned this code from somewhere else on the net as it seemed to give me the solution i am looking for … nothing too extravagant in my opinion as i simply want to have the background change itself randomly at a regular interval …

So i found that gsetting code … typed it into the shell logged in as a user and ran it and it worked! … so then made a script and run that … and that worked … pure layman logic suggested if i could get the system to run that same file when i was logged in then it should do the very same thing ??? But clearly that reasoning does not work!!

As an aside … there are two other ‘gnome’ applications that i had installed from the OpenSuse repositories … one was ‘glipper’ [a clipboard manager], the other escapes me at the moment … but neither would run without error … they both gave me ‘python errors’?? …

So out of desperation I gave OpenSuSe (12.2 Gnome) the flick and installed Mint 14 (cinnamon gnome version) … and none of the above issues occur!!! CRON executes my wallpaper scripts as expected … and ‘glipper’ no longer complains or crashes.

So, this begs the question: Perhaps my installation of OpenSuse 12.2 is missing some dependencies ??? … or I have i missed something during the installation??? … I thought I had followed the process accurately … and following the operating system installation the first thing i did was bring the system uptodate via YaST. So, from my level of expertise there really is not much else I can do.

From the research that I have done [and am able to understand] i would prefer to use OpenSuSe … so maybe when i get some more free time I will install the KDE version … somebody had suggested to me that it comes with a GUI facility to simply configure the background to change automatically??? But i must admit that I am left somewhat perplexed as to why I would be experiencing these anomalies!

However, thanks for all your help … it is very much appreciated.

Geoff

> i would prefer to use OpenSuSe

can’t help with your failing cron, but please give your shift key a
break, and begin to present our chosen the correct way:

openSUSE

btw, it never was SuSe…it was (in order of appearance, from the
beginning) S.u.S.E., SuSE, SUSE and now openSUSE®

with S.u.S.E. being an acronym for Software und System Entwicklung
(Software and Systems Development).
:slight_smile:

dd

On 2013-04-12 22:56, griadooss wrote:
> Okay … thanks for the help Hank … unfort I am no ‘admin’ … just a
> run-of-the-mill ex Windows user. I admit that I also am ‘not fluent’
> with ‘gsettings’ … have gleaned this code from somewhere else on the
> net as it seemed to give me the solution i am looking for … nothing
> too extravagant in my opinion as i simply want to have the background
> change itself randomly at a regular interval …

Gnome?

The standard way to do this in gnome 2 was to have the background
defined in an xml file. There is such a one predefined in openSUSE that
changes the background image morning, afternoon, evening, dawn.

Mine was:


<background>
<starttime>
<year>2009</year>
<month>01</month>
<day>06</day>
<hour>00</hour>
<minute>00</minute>
<second>00</second>
</starttime>

<static>
<duration>86400.0</duration>
<file>/usr/share/backgrounds/tierra/latierra.png</file>
</static>


</background>

What my cronjob did was change the image, then touch that xml file:
gnome then automatically reloaded the background image.

Or you can have the xml file defined to change the background images at
the times you want, there is a proper syntax for it.

I don’t know how gnome 3 has changed this, or if it has not changed.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)