Results 1 to 7 of 7

Thread: Cron and Unison Script

  1. #1
    Join Date
    Jan 2007
    Location
    Valencia, Spain
    Beans
    17
    Distro
    Ubuntu 10.04 Lucid Lynx

    Angry Cron and Unison Script

    Hi, I was reading all helps about how to configure Unison to work with cron, but was impossible for me.

    I write a simple script to use unison profile to syncronize my data:

    ---------------------------------------------------
    #!/bin/bash
    server1="192.168.1.2"
    server2="172.16.1.2"
    perfil="profile.prf"

    unison="$(which unison)"
    if ping -c 1 $server1
    then
    $unison $perfil
    elif ping -c 1 $server2
    then
    $unison $perfil
    else
    echo "No tiene Acceso al Server"
    fi
    date >> unison-script.log
    ---------------------------------------------------

    If I run this script from shell, it's do the work, but if I run this script from CRON, doesn't work the "unison" part, but the last line, the "log" work Ok.

    why??

    Thanks for your help or ideas!

  2. #2
    Join Date
    Sep 2006
    Location
    GA, USA
    Beans
    Hidden!
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Cron and Unison Script

    Couple of ideas for you. I'm not sure why it fails but I have seen this sort of thing before. Do you have a local MTA set up so cron can mail you errors? This may help figure it out.

    Asside from that check the cron environment. In particular make sure to set the path in there so it has all the same destinations you have. It may be as simple as the "which" command not finding your program in the path. Remember that when cron runs it doesn't use the exact environment of the user. Hope that helps.

  3. #3
    Join Date
    Jan 2007
    Location
    Valencia, Spain
    Beans
    17
    Distro
    Ubuntu 10.04 Lucid Lynx

    Angry Re: Cron and Unison Script

    Hi, thanks for you reply, but the script work ok if I use the :

    ./unison-script.sh

    and don't give me any error

  4. #4
    Join Date
    Sep 2006
    Location
    GA, USA
    Beans
    Hidden!
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Cron and Unison Script

    Quote Originally Posted by ferarg View Post
    Hi, thanks for you reply, but the script work ok if I use the :

    ./unison-script.sh

    and don't give me any error
    Yes that is my point. When you do that you are executing the script with your environment not the cron environment. They are not the same. In your term if you do echo $PATH you will see your path. Cron does not have that path unless you set it. Try setting these in your crontab:

    SHELL=/bin/bash
    PATH=/home/dweber/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

    Then see if it makes a difference.

  5. #5
    Join Date
    Jan 2007
    Location
    Valencia, Spain
    Beans
    17
    Distro
    Ubuntu 10.04 Lucid Lynx

    Angry Re: Cron and Unison Script

    Hi, thanks again.

    I copy&paste the "path" but no luck.

    I try to execute unison direct from cron:

    */2 * * * * /usr/bin/unison -batch profile.prf

    or

    */2 * * * * /usr/bin/unison profile.prf

    without any script and nothing, dont work!

  6. #6
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Cron and Unison Script

    Hi,
    try putting:
    Code:
    MAILTO=""
    at the top of your crontab

    There is an issue in Ubuntu with cronjobs which generate a lot of output. Cron tries to mail output to the user, but since there is no MTA (mail transfer agent) installed by default on Ubuntu desktop this output has nowhere to and when output is more than a certain buffer threshold the result is the command failing. Setting MAILTO to "" effectively turns off the mailing of output behaviour.

  7. #7
    Join Date
    Jan 2007
    Location
    Valencia, Spain
    Beans
    17
    Distro
    Ubuntu 10.04 Lucid Lynx

    Wink Re: Cron and Unison Script

    Thanks all of you for your help, this I can resolve it only with your ideas.

    Now I tell you what I did to run UNISON script correctly from CRON:

    1- install mailx (to watch the cron error)
    2- redirect all script outpoot to a "log file" (to watch if this give me some idea)
    3- activate cron logs in /etc/syslog.conf

    With all this, the "error" was that the "'/home/ferarg/.ssh/id_rsa" has a 755 permission, and for CRON this is "TOO OPEN", then I changed the permissions to 700 and all run correctly.

    Thanks for all your help!!!

Tags for this Thread

Bookmarks

Posting Permissions

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