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 ...
- 05-05-2010 #1Just 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:
And then I typed 'crontab -e' to edit the file and here is the contents....Code:#!/bin/bash cp ~/files/server_level.dat ~/files/backup/level_$(date +%s)
The shell script works when I run it manually, can't figure out why the cronjob isn't working.Code:# m h dom mon dow command 15,30,45,59 * * * * root ~/files/./mapbackup
Any help would be great.
I'm running Ubuntu 10 (Lucid) Server Edition.
- 05-06-2010 #2
ensure you have absolute path always.
- 05-06-2010 #3Just 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?
- 05-06-2010 #4
I typically avoid using ~, if anything use $HOME.
linux user # 503963
- 05-06-2010 #5Just 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.
- 05-06-2010 #6
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
- 05-06-2010 #7Just 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.
- 05-07-2010 #8Just 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.


Reply With Quote
