Find the answer to your Linux question:
Results 1 to 8 of 8
Hey, great forum. Found it very useful so, but needed to ask a question. I've been trying to create a backup script (yup, typical cronjob question) but am having problems ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    5

    Crontab - Location?


    Hey, great forum. Found it very useful so, but needed to ask a question.

    I've been trying to create a backup script (yup, typical cronjob question) but am having problems getting it to run. Here's what I've done so far...

    Written a shell script (called mapbackup) and put it within a folder in my home/ dir:


    Code:
    #!/bin/bash
    cp ~/files/server_level.dat ~/files/backup/level_$(date +%s)
    And then I typed 'crontab -e' to edit the file and here is the contents....

    Code:
    # m h  dom mon dow   command
    15,30,45,59 * * * * root ~/files/./mapbackup
    The shell script works when I run it manually, can't figure out why the cronjob isn't working.

    Any help would be great.

    I'm running Ubuntu 10 (Lucid) Server Edition.

  2. #2
    Just Joined! sathiya's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore, India
    Posts
    97
    ensure you have absolute path always.

  3. #3
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    Can I not use ~ in my script then? Because it is still an absolute pathway...

    /home/tim/files?

  4. #4
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    I typically avoid using ~, if anything use $HOME.
    linux user # 503963

  5. #5
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    Afraid it still hasn't worked, even with the absolute directories. Any more ideas anyone?

    Do I need to edit any other cron files within /etc/ or literally just 'crontab -e'? Does the folder I'm writing need certain permissions for cron?

    The script I wrote that it calls *definitely* works, I have tested it.

  6. #6
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    have you tried putting your cronjob under /etc/crontab instead of using the personal crontab? sometimes weird things happen like that.

    also i don't think you should specify "root" if you are using the personal crontab, as it will run as that person. the syntax (15,30,45,59 * * * * root ~/files/./mapbackup
    ) should work just fine inside of /etc/crontab

    however use of "." is probably not good. Cronjobs technically have no present working directory unless you specifically change to a directory when the script is executed.
    linux user # 503963

  7. #7
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    I edited the crontab file in /etc/ using vi... still no luck.

    Am I really misunderstanding something? It should be so simple.

  8. #8
    Just Joined!
    Join Date
    May 2010
    Posts
    5
    OK I've got it working, thanks for your help. Found an Ubuntu guide with some troubleshooting tips so I applied them all.

    When using a local user crontab (rather than root), you do not specify the user, otherwise it treats the username as the command! Pretty obvious really!

    Also a crontab needs to end in a newline, lastly I added my shell script to the $PATH variable, so I didn't need to use the ./ in the command.

    All is working now. Thanks 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
  •