This is a discussion on where and how to create a cron job within the Linux Operating System forums, part of the Unix Operating Systems category; --> dear everyone, i am a new user of linux os (specifically ubuntu v5.04)..i am setting up a dabase server ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| dear everyone, i am a new user of linux os (specifically ubuntu v5.04)..i am setting up a dabase server using this os. my problem is i wanted to create a scheduled task that would back up my database (every day, at night), but i dont know where and how am i gong to create it. i already have my scripts..my initial question is, do i have to create it on the text editor and save it as text? If yes, where will i save it, on the /etc/ cron.d directory?..My script would be something like this: #daily db backup 0 21 * * 1 /home/scripts/daily_mon.sh 0 21 * * 2 /home/scripts/daily_tue.sh 0 21 * * 3 /home/scripts/daily_wed.sh 0 21 * * 4 /home/scripts/daily_thu.sh 0 21 * * 5 /home/scripts/daily_fri.sh 0 21 * * 6 /home/scripts/daily_sat.sh 0 21 * * 0 /home/scripts/daily_sun.sh i tried creating it on the text editor and saving it as cronbackup.txt @ /etc/cron.d folder but is unable to save it. (Error: Could not save the file "/etc/cron.d/cronbackup) Your urgent help is much appreciated.. tnx grace |
| |||
| grace wrote: > dear everyone, > i am a new user of linux os (specifically ubuntu v5.04)..i am setting > up a dabase server using this os. my problem is i wanted to create a > scheduled task that would back up my database (every day, at night), > but i dont know where and how am i gong to create it. i already have > my scripts..my initial question is, do i have to create it on the text > editor and save it as text? If yes, where will i save it, on the /etc/ > cron.d directory?..My script would be something like this: > > > #daily db backup > 0 21 * * 1 /home/scripts/daily_mon.sh > 0 21 * * 2 /home/scripts/daily_tue.sh > 0 21 * * 3 /home/scripts/daily_wed.sh > 0 21 * * 4 /home/scripts/daily_thu.sh > 0 21 * * 5 /home/scripts/daily_fri.sh > 0 21 * * 6 /home/scripts/daily_sat.sh > 0 21 * * 0 /home/scripts/daily_sun.sh > > i tried creating it on the text editor and saving it as cronbackup.txt > @ /etc/cron.d folder but is unable to save it. (Error: Could not save > the file "/etc/cron.d/cronbackup) > I run Red Hat Enterprise Linux, and for that things seem a bit different. 1.) There is a single file, /etc/crontab that is used to run the standard system jobs. Mine is like this: $ cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=me@localhost.localdomain HOME=/ # M is minute to start: 00 - 59 # H is hour to start; 00 - 23 # D is day of month to start: 01 - 31 # m is month to start: 01 - 12 -- 01 is January, etc. # d is day of week to start: 00 - 06 -- 00 is Sunday, etc. # run-parts # cron.daily is run Monday - Saturday. # cron.weekly is run Sunday only. # Do not start things from 01:00 to 02:59 because they will run twice # when the fall switch from daylight savings time to standard time occurs, # and may be skipped in the spring when 2:00 AM is skipped. # N.B.: this may not be necessary if you are running newer versions # versions of crond. #M H D m d user program arguments 01 * * * * root run-parts /etc/cron.hourly 04 1 * * 1-6 root run-parts /etc/cron.daily 04 3 * * 0 root run-parts /etc/cron.weekly 19 4 1 * * root run-parts /etc/cron.monthly If you really need to do something different each day of the week, you could set up /etc/cron.monday, etc., and add suitable lines similar to the cron.weekly line here to get that. run-parts is a program that will run all the programs in the directory specified by the argument. 2.) In each of these directories, I have entries similar to this: $ ls -l /etc/cron.weekly/ total 8 lrwxrwxrwx 1 root root 30 Dec 30 2004 00-logwatch -> /etc/log.d/scripts/logwatch.pl lrwxrwxrwx 1 root root 25 Dec 30 2004 logrotate -> /etc/cron.daily/logrotate -rwxr-xr-x 1 root root 414 Nov 8 2005 makewhatis.cron lrwxrwxrwx 1 root root 23 Dec 30 2004 prelink -> /etc/cron.daily/prelink lrwxrwxrwx 1 root root 19 Dec 30 2004 rpm -> /etc/cron.daily/rpm lrwxrwxrwx 1 root root 28 Dec 30 2004 slocate.cron -> /etc/cron.daily/slocate.cron lrwxrwxrwx 1 root root 26 Dec 30 2004 tetex.cron -> /etc/cron.daily/tetex.cron lrwxrwxrwx 1 root root 24 Dec 30 2004 tmpwatch -> /etc/cron.daily/tmpwatch lrwxrwxrwx 1 root root 30 Dec 30 2004 tripwire-check -> /etc/cron.daily/tripwire-check lrwxrwxrwx 1 root root 28 Dec 30 2004 up2date.trim -> /etc/cron.daily/up2date.trim -rwxr-xr-- 1 root root 2551 Nov 14 18:11 zBackup.cron The zBackup.cron file has the script to do a backup for the required day. Its contents depend on your backup program, etc. These files can all be made with any text editor. I happen to use emacs, but vi would do as well. Use whatever one you are most familiar with. 3.) All the above assumes you are a system administrator who is doing backups for the entire machine. If you want to just do backups of your own files, the way to do that is to use the crontab program. man crontab will get you that program. You should not edit the stuff in /var/spool/cron directly. Unless Ubuntu is very different, you do not want to mess with /etc/cron.d -- .~. Jean-David Beyer Registered Linux User 85642. /V\ PGP-Key: 9A2FC99A Registered Machine 241939. /( )\ Shrewsbury, New Jersey http://counter.li.org ^^-^^ 06:15:01 up 82 days, 17:44, 3 users, load average: 4.42, 4.27, 4.12 |
| |||
| grace wrote: > dear everyone, > i am a new user of linux os (specifically ubuntu v5.04)..i am setting > up a dabase server using this os. my problem is i wanted to create a > scheduled task that would back up my database (every day, at night), > but i dont know where and how am i gong to create it. i already have > my scripts..my initial question is, do i have to create it on the text > editor and save it as text? If yes, where will i save it, on the /etc/ > cron.d directory?..My script would be something like this: > > > #daily db backup > 0 21 * * 1 /home/scripts/daily_mon.sh > 0 21 * * 2 /home/scripts/daily_tue.sh > 0 21 * * 3 /home/scripts/daily_wed.sh > 0 21 * * 4 /home/scripts/daily_thu.sh > 0 21 * * 5 /home/scripts/daily_fri.sh > 0 21 * * 6 /home/scripts/daily_sat.sh > 0 21 * * 0 /home/scripts/daily_sun.sh > > i tried creating it on the text editor and saving it as cronbackup.txt > @ /etc/cron.d folder but is unable to save it. (Error: Could not save > the file "/etc/cron.d/cronbackup) > There are two ways of solving the problem: 1) You could add your scripts to the standard cron scripts already installed on your system. These are all fired off by a system crontab file in /etc. This is probably best left alone unless you really know what you are doing. 2) You could add your own personal scripts using crontab. I would recommend this approach. You need to undertake this as the user who you want to be running the scripts: a) Create a crontab file - pretty much as you have already for more details type: man 5 crontab b) Run crontab to install your crontab file. Type: crontab yourfilename c) You can check the crontab that is installed by: crontab -l For more details: man crontab man 5 crontab Regards JohnT |
| |||
| On 10 May 2007 03:14:11 -0700, grace wrote: > dear everyone, > i am a new user of linux os (specifically ubuntu v5.04). That is getting kinda long in the tooth isn't it.? > > i tried creating it on the text editor and saving it as cronbackup.txt > @ /etc/cron.d folder but is unable to save it. (Error: Could not save > the file "/etc/cron.d/cronbackup) Well if you can not click up a terminal and do a cp cronbackup.txt /etc/cron.d/cronbackup.txt then I will have to guess you are not doing the command logged in as root. Also you may want to do a chmod +x cronbackup.txt ./cronbackup.txt before putting it in /etc/cron.d to verify it at least works. I would have just one script, and it would decide what to do based on day of the week instead of having a script for each day of the week. If you have a separate script because of output backup name then you can use something like _bk_fn=$(/bin/date '+%a').sql See echo $_bk_fn For extra points: http://tldp.org/LDP/abs/html/index.html |
| |||
| On 10 May 2007 03:14:11 -0700, grace <zympoul@gmail.com> wrote: > > > dear everyone, > i am a new user of linux os (specifically ubuntu v5.04)..i am setting > up a dabase server using this os. my problem is i wanted to create a > scheduled task that would back up my database (every day, at night), > but i dont know where and how am i gong to create it. i already have > my scripts..my initial question is, do i have to create it on the text > editor and save it as text? If yes, where will i save it, on the /etc/ > cron.d directory?..My script would be something like this: > > > #daily db backup > 0 21 * * 1 /home/scripts/daily_mon.sh > 0 21 * * 2 /home/scripts/daily_tue.sh > 0 21 * * 3 /home/scripts/daily_wed.sh > 0 21 * * 4 /home/scripts/daily_thu.sh > 0 21 * * 5 /home/scripts/daily_fri.sh > 0 21 * * 6 /home/scripts/daily_sat.sh > 0 21 * * 0 /home/scripts/daily_sun.sh > > i tried creating it on the text editor and saving it as cronbackup.txt > @ /etc/cron.d folder but is unable to save it. (Error: Could not save > the file "/etc/cron.d/cronbackup) > You need to use sudo to edit a file in /etc/cron.d or anywhere other than your home directory or /tmp. You can use the command "crontab -e" to edit your personal crontab (any commands in there will be executed as you, not as root). /etc/crontab and /etc/cron.d files have the format minute hour dayofmonth month dayofweek USER command -- The computer is to the information industry roughly what the central power station is to the electrical industry. -- Peter Drucker |
| ||||
| Ayon kay Bill Marcum: > On 10 May 2007 03:14:11 -0700, grace > <zympoul@gmail.com> wrote: > > > > > > dear everyone, > > i am a new user of linux os (specifically ubuntu v5.04)..i am setting > > up a dabase server using this os. my problem is i wanted to create a > > scheduled task that would back up my database (every day, at night), > > but i dont know where and how am i gong to create it. i already have > > my scripts..my initial question is, do i have to create it on the text > > editor and save it as text? If yes, where will i save it, on the /etc/ > > cron.d directory?..My script would be something like this: > > > > > > #daily db backup > > 0 21 * * 1 /home/scripts/daily_mon.sh > > 0 21 * * 2 /home/scripts/daily_tue.sh > > 0 21 * * 3 /home/scripts/daily_wed.sh > > 0 21 * * 4 /home/scripts/daily_thu.sh > > 0 21 * * 5 /home/scripts/daily_fri.sh > > 0 21 * * 6 /home/scripts/daily_sat.sh > > 0 21 * * 0 /home/scripts/daily_sun.sh > > > > i tried creating it on the text editor and saving it as cronbackup.txt > > @ /etc/cron.d folder but is unable to save it. (Error: Could not save > > the file "/etc/cron.d/cronbackup) > > > You need to use sudo to edit a file in /etc/cron.d or anywhere other > than your home directory or /tmp. You can use the command "crontab -e" > to edit your personal crontab (any commands in there will be executed as > you, not as root). > > /etc/crontab and /etc/cron.d files have the format > minute hour dayofmonth month dayofweek USER command > > > -- > The computer is to the information industry roughly what the > central power station is to the electrical industry. > -- Peter Drucker Tnx sir. i tried using crontab -e and my back-up scheduling is now ok...tnx so mch |