Results 1 to 9 of 9

Thread: Backup Script trouble

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Location
    Costa Rica
    Beans
    255
    Distro
    Ubuntu 10.04 Lucid Lynx

    Backup Script trouble

    Hi all,

    I wrote a very small and simple script to stop a service, backup a folder, copy it to a remote location via scp and then start the service again.

    Everything works except for one thing, the service does not want to start for some reason, I have to manually ssh into the server and execute the comand to start it.

    Here is the script, like I said, nothing fancy:

    Code:
    #!/bin/bash
    FILE=openbravo$(date +"%d-%m-%y").tar.gz
    /etc/init.d/openbravo stop
    cd /opt
    tar cvzf $FILE OpenbravoERP-3.0
    scp $FILE 123.123.123.123:/REMOTE/LOCATION
    /etc/init.d/openbravo start
    If I input the last command on the command line it works no problem, its only when the scheduled job runs that I run into this issue.

    I have also tried putting the scp command at the end to see if it made any difference, but same problem.

    How can I debug this?

    thanks a lot for the help!

    ps: I checked the scp command above and its completing succesfully (I can see the file on the remote location).
    Last edited by X1R1; October 12th, 2012 at 08:01 PM.
    Linux User#498977
    There are only 10 types of people in the world. Those who understand binary, and those who dont.
    My Blog about Linux and other stuff

  2. #2
    Join Date
    Nov 2006
    Location
    Belgium
    Beans
    3,008
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Backup Script trouble

    does the entire script works when you run it manually ?
    if not, what does it say ?

    Dou you suppress output from cron ? It usually logs or sends mail if a cron job produces output, such as an error msg. You want to see those.

  3. #3
    Join Date
    Nov 2006
    Location
    Belgium
    Beans
    3,008
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Backup Script trouble

    wild guess:

    the '/etc/init.d/openbravo start' is not executed because your script hangs on the preceding command;

    therefore : assume the script fails on 'scp $FILE ... ... ' fails, possibly because cron runs as root and root can not logon to the target server.

  4. #4
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    515
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Backup Script trouble

    What user are you scheduling this script to run as?

    Can the service only be shutdown using root privileges?

    EDIT #1: Also, when using scripts, be sure to include the FULL path to everything...never assume a current working directory.

    e.g. Full path for the archive file in your FILE variable.

    It would also be wise to checked the return code of any command you run so you can handle the exceptional case of when it doesn't work. Did the tar command work? Did the copy command work? Did the service actually stop...did it actually start? These are all things you really need to know when automating such tasks. I would include a bit of code to include sending email notifications whenever (not if) it fails.

    EDIT #2: I include a path in my crontab schedule to help avoid these problems...but I still specify full paths whenever I can. LOOK HERE

    LHammonds
    Last edited by LHammonds; October 15th, 2012 at 02:32 PM.

  5. #5
    Join Date
    Apr 2012
    Beans
    5,386

    Re: Backup Script trouble

    I agree it's likely a environment (PATH) thing - you may need to give a path to start/stop as well (which are also commands - in /sbin) not just the 'service' command (in /usr/sbin) - see this post

    http://ubuntuforums.org/showpost.php...94&postcount=4
    Last edited by steeldriver; October 12th, 2012 at 11:41 PM.

  6. #6
    Join Date
    Oct 2005
    Location
    Al Ain
    Beans
    7,914

    Re: Backup Script trouble

    Howdy,

    Check the paths in the /etc/init.d/openbravo script and expand them all. Cron runs with a very limited environment setup.

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
  •