Results 1 to 7 of 7

Thread: Commands not working in crontab

  1. #1

    Default Commands not working in crontab

    I have the following two lines in my crontab:
    0 5 * * 1-5 DISPLAY=:0 amarok -p
    45 6 * * 1-5 DISPLAY=:0 qdbus org.ktorrent.ktorrent /core org.ktorrent.core.setSuspended false > /dev/null
    Both commands work when I enter them in the terminal (with the "DISPLAY=:0" part removed). None or the commands work from crontab. The first one (amarok) gives the following mailed to me:
    unnamed app(9705): KUniqueApplication: Cannot find the D-Bus session server: "/bin/dbus-launch terminated abnormally with the following error: No protocol specified
    Autolaunch error: X11 initialization failed.
    "

    unnamed app(9685): KUniqueApplication: Pipe closed unexpectedly.
    The second one (ktorrent) gives this:
    Could not connect to D-Bus server: org.freedesktop.DBus.Error.Spawn.ExecFailed: /bin/dbus-launch terminated abnormally with the following error: No protocol specified
    Autolaunch error: X11 initialization failed.

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

    Default Re: Commands not working in crontab

    On 2013-09-04 19:46, Per 68 wrote:
    >
    > I have the following two lines in my crontab:
    >>
    >> 0 5 * * 1-5 DISPLAY=:0 amarok -p
    >> 45 6 * * 1-5 DISPLAY=:0 qdbus org.ktorrent.ktorrent /core
    >> org.ktorrent.core.setSuspended false > /dev/null


    That's 3 lines.

    Please, this is difficult to decipher, because lines have wrapped round.
    Please use code tags for command outputs and listings - the '#' in the
    web editor.
    View this thread for instructions



    Besides that, you can not call a GUI from cron.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 11.4, with Evergreen, x86_64 "Celadon" (Minas Tirith))

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,851

    Default Re: Commands not working in crontab

    Those commands run in the background. It is not even sure that X is running. When X is running, It is not sure that a GUI user is loged in. And even if a GUI user is loged in and is using DISPLAY 0:0 processes may not be allowed to open windows on a display without consent of the owner of that display. Not even root is allowed to do that.
    Henk van Velden

  4. #4

    Default Re: Commands not working in crontab

    Sorry. Here's the same using CODE tags:
    Code:
    0 5 * * 1-5 DISPLAY=:0 amarok -p
    45 6 * * 1-5 DISPLAY=:0 qdbus org.ktorrent.ktorrent /core org.ktorrent.core.setSuspended false > /dev/null
    I've googled "amarok cron" and found many questions similar to mine. The answer has been to add DISPLAY=:0 to the beginning of the command line and the person asking the question has said it worked in all threads I looked into. These has been gqustions mostly from Ubuntu users, but also from users of Arch and Gentoo. I know from personal experience that it worked on Mageia before I changed to openSUSE. It even worked for me for 2 days a couple of weeks back in openSUSE. It then stopped working without me editing the crontab. Both Amarok and Ktorrent is already running when these commands are executed if that matters.

  5. #5
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    26,487
    Blog Entries
    15

    Default Re: Commands not working in crontab

    Quote Originally Posted by Per_68 View Post
    Sorry. Here's the same using CODE tags:
    Code:
    0 5 * * 1-5 DISPLAY=:0 amarok -p
    45 6 * * 1-5 DISPLAY=:0 qdbus org.ktorrent.ktorrent /core org.ktorrent.core.setSuspended false > /dev/null
    I've googled "amarok cron" and found many questions similar to mine. The answer has been to add DISPLAY=:0 to the beginning of the command line and the person asking the question has said it worked in all threads I looked into. These has been gqustions mostly from Ubuntu users, but also from users of Arch and Gentoo. I know from personal experience that it worked on Mageia before I changed to openSUSE. It even worked for me for 2 days a couple of weeks back in openSUSE. It then stopped working without me editing the crontab. Both Amarok and Ktorrent is already running when these commands are executed if that matters.
    Hi
    Cron by default knows no paths to files etc, have you tried exporting the DISPLAY variable first in your crontab and add the full path to amorak and qdbus;
    Code:
    export DISPLAY=":0"
    0 5 * * 1-5 /usr/bin/amarok -p
    45 6 * * 1-5 /usr/bin/qdbus org.ktorrent.ktorrent /core org.ktorrent.core.setSuspended false > /dev/null
    Assuming both programs are in /usr/bin, you could also set the PATH statement in your crontab. I'm assuming this is for showing some status of those programs?
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  6. #6

    Default Re: Commands not working in crontab

    Adding the path to the commands did unfortunately not change anything.

  7. #7

    Default Re: Commands not working in crontab

    I've solved the problem, or at least found a workaround. The line in crontab doesn't work if I reboot my computer, but if I log out and log in again as the same user it starts working again.

Posting Permissions

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