Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: crontab ???

  1. #1
    Join Date
    Apr 2013
    Location
    Sydney, AU
    Posts
    243

    Default crontab ???

    Created this file called 'wallpaperchanger' using crontab -e

    Code:
    * * * * * /home/USER/bin/wallpaperchanger > /home/USER/Documents/cron.log
    the script 'wallpaperchanger' reads thus:

    Code:
    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\nAutolaunch error: X11 initialization failed.\n
    What can be wrong??

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

  2. #2
    Join Date
    Mar 2010
    Location
    Austin - Texas
    Posts
    10,140
    Blog Entries
    48

    Question Re: crontab ???

    Quote Originally Posted by griadooss View Post
    Created this file called 'wallpaperchanger' using crontab -e

    Code:
    * * * * * /home/USER/bin/wallpaperchanger > /home/USER/Documents/cron.log
    the script 'wallpaperchanger' reads thus:

    Code:
    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!!




    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,
    My Blog: https://forums.opensuse.org/blogs/jdmcdaniel3/

    Software efficiency halves every 18 months, thus compensating for Moore's Law

    Its James again from Austin, Texas

  3. #3
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,487
    Blog Entries
    2

    Default Re: crontab ???

    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
    Code:
    systemctl status cron.service
    View the contents of the config file
    Code:
    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)
    Code:
    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

  4. #4
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: crontab ???

    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)

  5. #5
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: crontab ???

    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)

  6. #6
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,399

    Default Re: crontab ???

    In any case, your posting of your script is not realy interpretable. You should do a
    Code:
    ls -l /home/USER/bin/wallpaperchanger
    and
    Code:
    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.
    Henk van Velden

  7. #7
    Join Date
    Apr 2013
    Location
    Sydney, AU
    Posts
    243

    Default Re: crontab ???

    Quote Originally Posted by tsu2 View Post
    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
    Code:
    systemctl status cron.service
    View the contents of the config file
    Code:
    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)
    Code:
    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
    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

  8. #8
    Join Date
    Apr 2013
    Location
    Sydney, AU
    Posts
    243

    Default Re: crontab ???

    Quote Originally Posted by robin_listas View Post
    On 2013-04-07 04:46, griadooss wrote:
    > Created this file called 'wallpaperchanger' using crontab -e


    which user does the "crontab -e"?

    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??

  9. #9
    Join Date
    Apr 2013
    Location
    Sydney, AU
    Posts
    243

    Default Re: crontab ???

    Quote Originally Posted by hcvv View Post
    In any case, your posting of your script is not realy interpretable. You should do a
    Code:
    ls -l /home/USER/bin/wallpaperchanger
    and
    Code:
    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.

    Okay ... good point .. so here are the outputs

    Code:
    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

    Code:
    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:


    Code:
    From griadooss@linux-9ar1.site  Fri Apr 12 20:10:02 2013
    Return-Path: <griadooss@linux-9ar1.site>
    X-Original-To: griadooss
    Delivered-To: griadooss@linux-9ar1.site
    Received: by linux-9ar1.site (Postfix, from userid 1000)
        id 0E30EDF706; Fri, 12 Apr 2013 20:10:02 +1000 (EST)
    From: griadooss@linux-9ar1.site (Cron Daemon)
    To: griadooss@linux-9ar1.site
    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\nAutolaunch error: X11 initialization failed.\n
    
    ** (process:6856): WARNING **: Command line `dbus-launch --autolaunch=aaf45848b77796875f161bed0000071b --binary-syntax --close-stderr' exited with non-zero exit status 1: No protocol specified\nAutolaunch error: X11 initialization failed.\n
    and the cron job

    Code:
    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

  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,399

    Default Re: crontab ???

    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.
    Last edited by hcvv; 12-Apr-2013 at 05:12.
    Henk van Velden

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •