Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
01-04-2006, 01:23 AM
|
#1
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 966
Rep:
|
Using cron
I'm following a back up idea on this link http://esm2.imt-mrs.fr/~staffelb/gui...art1/cron.html
Quote:
Putting Theory Into Practice
Here's a handy little automation exercise for you to try out. It will backup the contents of your home directory to a .tar.gz file each morning at 2.30a.m.
If you haven't already done so, enter:
su -c 'pico /etc/cron.allow'
...and add your username to this file to allow you to submit crontab files.
- 1 -
If you're not already in your home directory, enter:
cd
- 2 -
Enter:
pico backup
...and enter the following:
--------------------------------------------------------------------------------
rm backup.tar.gz
tar cfz backup.tar.gz .
--------------------------------------------------------------------------------
...then press Ctrl+o to save the file, and Ctrl+x to exit.
- 3 -
Now make the script executable by entering:
chmod +x backup
- 4 -
Enter:
crontab -e
- 5 -
Press i to enter Insert mode and enter the following:
--------------------------------------------------------------------------------
30 2 * * * ./backup
--------------------------------------------------------------------------------
...then press Esc to return to Command mode, and enter:
:wq
|
The only way I can get it to back a DIR of ours is to use the command line only ./backup
cron doesn't seem to be working
[root@localhost subs]# crontab -l
40 13 * * * ./usr/local/awstats/wwwroot/cgi-bin/./awstats.pl -update -config=www.rockinghamgateway.com
20 14 * * * ./srv/www/subs/backup
[root@localhost subs]#
I tried a few different ways by testing it by editing the crontab a few minutes forward to see if they are updateding or backing up.
hope that makes sence.
??? ??? ???
TT
|
|
|
01-04-2006, 02:35 AM
|
#2
|
Member
Registered: Oct 2005
Distribution: Slackware
Posts: 228
Rep:
|
tommytomato:
I believe the error is with your "tar" command.
Change from:
Code:
tar cfz backup.tar.gz .
To:
Code:
tar czf backup.tar.gz .
The backup file's name must directly follow the "f" option.
Give that a whirl and let me know if it worked for you.
|
|
|
01-04-2006, 03:03 AM
|
#3
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 966
Original Poster
Rep:
|
Nup nothing happing
10 * * * 0,1,2,3,4,5,6,7 /usr/local/awstats/tools/awstats_updateall.pl now >/dev/null 2>&1p
02 16 * * * ./srv/www/subs/backup
top one works and the 2nd one dont.
Code:
crontab -l
10 * * * 0,1,2,3,4,5,6,7 /usr/local/awstats/tools/awstats_updateall.pl now >/dev/null 2>&1p
02 16 * * * ./srv/www/subs/backup
file back up has perm 0755 and has this in side the file
Code:
rm backup.tar.gz
tar czf backup.tar.gz .
file was saved as backup, if I use the command line #./backup it works.
TT
|
|
|
01-04-2006, 03:27 AM
|
#4
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
Look at cron's logs to see what's happening.
Furthermore, cron uses it's own environment variables. $PWD, the present working directory, is one of them.
So I'm not sure "./", which is synonymous to $PWD, is set up correctly. In other words, I doubt if cron
can actually find your command, since it may not be running out of the directory that you expect it to.
It would be a good idea to change "./..." into an absolute path, or use ~root/ for the home directory of the
user root.
A alternative is to add the command
cd (or cd to your root's home dir)
to the top of your backup script, just to make sure it's running in the right directory.
A 3rd option is to specify absolute paths in the "rm" and "tar" commands.
If "./backup" works, assuming you're inside your home directory, then why do you ask cron to run it as
"./srv/www/subs/backup" (assuming for a moment that cron runs the commands out of your home directory)?
Shouldn't it simply be "./backup" instead? In other words, pay attention to the paths!
If you're worried that your path is wrong, try adding "ls" to the cron command:
02 16 * * * ls -l ./srv/www/subs/backup
This should send you an e-mail containing the output of the ls -l command. If it doesn't, add "> a_new_file" at the
end to make "ls" write it's output to a regular file (so you can read it afterwards).
|
|
|
01-04-2006, 03:30 AM
|
#5
|
Member
Registered: Oct 2005
Distribution: Slackware
Posts: 228
Rep:
|
How about specifying the full paths:
Code:
rm /full/path/to/backup.tar.gz
tar czf /full/path/to/backup.tar.gz .
|
|
|
01-04-2006, 04:31 AM
|
#6
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 966
Original Poster
Rep:
|
I've done what you guys said, and still no go, must be missing someting
my cron is
10 * * * 0,1,2,3,4,5,6,7 /usr/local/awstats/tools/awstats_updateall.pl now >/dev/null 2>&1p
27 17 * * * ./srv/www/subs/backup
I added that path into the backup file under subs
rm /srv/www/subs/backup.tar.gz
tar czf /srv/www/subs/backup.tar.gz .
must be the way I do my crons even the top cron is not work, I thought it was, OS is tinysofa odin
TT
Last edited by tommytomato; 01-04-2006 at 04:33 AM.
|
|
|
01-04-2006, 05:20 AM
|
#7
|
Member
Registered: Oct 2005
Distribution: Slackware
Posts: 228
Rep:
|
Is crond running???
Try "pidof crond", or "ps aux | grep crond" to see.
If it's not, then fire it up and verify that at least one of your crons is running.
|
|
|
01-04-2006, 05:21 AM
|
#8
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
First of all, be carefull about the paths.
/srv/www/subs/backup.tar.gz
is NOT the same as
./srv/www/subs/backup.tar.gz
Secondly, to check if cron works, follow the following steps:
-Check if the cron daemon (crond) is running.
This can be done via the "ps" command (eg ps -efl|grep -i crond) or via
/sbin/chkconfig --list | grep -i cron
Via /sbin/service cron status (or something like that) may also work.
Seems WindowBreaker beat me to this one... - lol
-Secondly, your user must be allowed to run cron jobs. In other words, your username must appear in
the file /etc/cron.allow. If cron.allow doesn't exist, then your username may not appear in /etc/cron.deny.
If cron.deny and cron.allow do not exist, then you must create the cron.allow file and put "root" as well as
your username inside it. Be sure to create it as root.
For more info, see:
man cron
man crontab
man 8 crontab
|
|
|
01-04-2006, 10:24 AM
|
#9
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 966
Original Poster
Rep:
|
ok guys thanks
I had to have a break so I went fishing, I'll double check every thing in the morning because I'm nacked.
I checked to see if cron is running here is what I get
Quote:
ps -efl|grep -i crond
1 S root 1965 1 0 76 0 - 1079 - 12:22 ? 00:00:00 crond
0 R root 3794 3759 0 79 0 - 1072 - 23:21 pts/0 00:00:00 grep -i crond
|
Also I dont have /etc/cron.allow in my system
Quote:
First of all, be carefull about the paths.
/srv/www/subs/backup.tar.gz
is NOT the same as
./srv/www/subs/backup.tar.gz
|
So which is the correct one, I have the top one /srv/www/subs/backup.tar.gz
TT
|
|
|
01-04-2006, 11:23 AM
|
#10
|
Senior Member
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515
Rep:
|
By the looks of it, your cron daemon is running alright.
Do you have /etc/cron.deny? If so, make sure that your user isn't listed in that file.
If you don't, then "su" to root, create the file /etc/cron.allow and put your username in there.
Something like:
su #switches to root user, you'll need the password...
echo "your_username_goes_here" > /etc/cron.allow
exit #exits su
(the text after the '#' sign are just comments, they are not executed by your system)
As to which is the right path, that depends on the directory you're working in.
Paths starting in "/" are called absolute paths. They are subdirectories located under
the "/" (top-level) directory of your disk.
The path that starts with "./" is different. "./" refers to the current directory (use the "pwd" command to see what it is). So, ./srv/www/subs/backup.tar.gz is located somewhere under the current directory, which may or may not be the "/" directory.
You can actually use any path you want. You just need to decide:
-where (in which directory) you want to store the backup.tar.gz file
-where the files you need to backup are stored.
|
|
|
01-04-2006, 11:34 AM
|
#11
|
LQ Guru
Registered: Jan 2001
Posts: 24,149
|
Remove the . in the ./srv... should result in the script executing from cron. You only use a ./ in front of a command when your in a directory that has an executable that isn't in your present PATH. If your specifying the full path, you never need to put a . in the path name.
|
|
|
01-04-2006, 12:28 PM
|
#12
|
Member
Registered: Sep 2003
Location: Manchester UK
Posts: 264
Rep:
|
If you ask me, the entire tutorial is written badly.
Surely "tar -zcf backup.tar.gz ." should be in a bash script? So therefore:
Code:
#!/bin/bash
# this file is an automated backup script, backup.sh.
cd ~
rm backup.tar.gz
tar -zcf backup.tar.gz .
Would make more sense?
I know that the #!/bin/bash isn't completely necessary, but there just doesn't seem to be any thought put into it.
|
|
|
01-05-2006, 08:06 PM
|
#13
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 966
Original Poster
Rep:
|
Quote:
If you ask me, the entire tutorial is written badly.
|
Thats what I was thinking hey, while having a break and fishing I was thinking the same thing, I haven't had alot to do with scripts, but the ones I have use all start with #!/bin/bash.
So thanks again I'm going to give it another shot today
timmeke
I'm using root all the time, so do I still need to create that /etc/cron.allow folder ?
TT
Last edited by tommytomato; 01-05-2006 at 08:11 PM.
|
|
|
01-05-2006, 08:40 PM
|
#14
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 966
Original Poster
Rep:
|
ok here is what I did,
I renamed the backup file to backup.sh for starters then I edited the file like so.
Code:
!/bin/bash
# this file is an automated backup script, backup.sh.
cd ~
rm backup.sh.tar.gz
tar -zcf backup.sh.tar.gz .
#rm /srv/www/subs/backup.tar.gz
#tar czf /srv/www/subs/backup.tar.gz .
then I edited my crontab like so, working only with backup.sh for now
Quote:
[root@localhost]# crontab -l
10 * * * 0,1,2,3,4,5,6,7 /usr/local/awstats/tools/awstats_updateall.pl now >/dev/null 2>&1p
30 9 * * * /srv/www/subs/backup.sh
|
Then I put the time foward a bit and waited for the backup to work, which it didn't to a point, but some how that crontab created a backup.sh.tar.gz file under the path /root/
I'm just wondering if the pathis wrong, the script jumps back to root dir cd ~is that correct if so should it be cd /srv/www/subs/
TT
|
|
|
01-05-2006, 08:47 PM
|
#15
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 14.0.4 - Server Ubuntu 14.04.5 LTS
Posts: 966
Original Poster
Rep:
|
Well guys it was the path
it now works, thanks for the help and tips, need to find out why the awstats one wont work.
TT
|
|
|
All times are GMT -5. The time now is 05:08 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|