[Novalug] Cron

pereira ninorpereira@gmail.com
Sun Apr 26 17:20:23 EDT 2015


Jon,

after roaming around in the system some, trying to find where all these
files are (with e.g., 'locate cron' I finally find my crontab file. It 
is where
you said it would be, but it's not called 'crontab':
it is /var/spool/crontabs/pereira

when I do 'crontab -l' I get what's in it: a (useful) bunch of text, and 
then the command:

0 3 * * * /home/pereira/bin/backup >> 1>/home/pereira/zzzzz-backup.log

which I put there in a previous exercise to accomplish the same thing. 
That didn't work.

Now that I'm ever so slightly more educated, I try this command just to 
see if
it will work. It doesn't, there's an error. No wonder it never worked.
I play a little with the commands, and find out that
everything starting with the '>>' isn't strictly necessary. So, I leave 
that out.

Here's hoping that a backup will be done at 3 am....

Thank you for your help.

Nino



pereira@p:/etc/default$ more cron
# This file has been deprecated. Please add custom options for cron to
# /etc/init/cron.conf and/or /etc/init/cron.override directly. See
# the init(5) man page for more information.


On 04/26/2015 04:14 PM, Jon LaBadie wrote:
> On Sun, Apr 26, 2015 at 04:00:00PM -0400, pereira wrote:
>> Jon,
>>
>> somehow I sort of hoped that you might read this cry for help,
>> and react with something useful. You did it! Thank you.
>>
>> Now I have to study....
>>
> For now, skip to the end where it says run "crontab -e"
> which puts you in an editor.  Enter the one line I gave
> you "4 2 * * * ...", save it,  and quit the editor.
>
> The read and if needed, modify.
>
>> Nino
>>
>>
>> On 04/26/2015 03:56 PM, Jon LaBadie wrote:
>>> On Sun, Apr 26, 2015 at 09:54:50AM -0400, pereira via Novalug wrote:
>>>> Thanks to an earlier discussion, I'm reasonably happy with a
>>>> backup script that user rsync to copy files that I hate to lose
>>>> onto a second disc. The problem is: I don't know how to schedule
>>>> having this script executed sometime every 24 hours.
>>>>
>>>> I understood that the best way to do this is to put a link to this script
>>>> in the directory /etc/cron.daily. This directory contains the scripts that
>>>> are executed daily, sometime (like, 2 am).  My directory now looks like:
>>> Nino,
>>>
>>> Are you doing this for personal files, i.e. ones you will be able
>>> to read and not rely on root privileges to backup?
>>>
>>> If so, I'd prefer personal crontab files rather than system cron's.
>>> I'll address how at the end.
>>>
>>>> pereira@p:/etc/cron.daily$ ls -tor
>>>> total 92
>>>> -rwxr-xr-x 1 root   311 Jun 20  2010 0anacron
>>>> -rwxr-xr-x 1 root  2417 Jul  1  2011 popularity-contest
>>>> (snip)
>>>> lrwxrwxrwx 1 root    24 Apr  6 20:25 backup -> /home/pereira/bin/backup
>>>>
>>>> The first one, 0anacron, contains essentially a single line,
>>>> anacron -u cron.daily
>>>>
>>>> where the flag '-u' means (from the man page):
>>>>   -u     Only update the timestamps of the jobs, to the current date, but
>>>> don't run anything.
>>>>
>>>> Do I understand correctly that anacron now doesn't run any jobs in
>>>> /etc/cron.daily?
>>>> If so, how do I make it run?
>>> I don't know the details.  My system has only one file called "0anacron"
>>> but it is in /etc/cron.hourly.  The file is 17 lines long and ends with
>>> "anacron -s".
>>>
>>>> I look in a file 'anacrontab', which is supposed to tell me what gets
>>>> executed.
>>>> I find that this tells it to execute another program, run-parts, which,
>>>> on looking at the man page, makes my mind boggle.
>>> If I recall correctly, run-parts checks which if any of the hourly,
>>> daily, weekly, monthly stuff needs to be run.  If so, it visits the
>>> appropriate directory and executes the programs it finds.
>>>
>>>> So, where and how do I specify the files to be run daily/weekly/....
>>> Check out "ls -ld /etc/cron.*".  You will probably find directories for
>>> cron.hourly, as well as monthly and weekly.
>>> With personal cron tables you will have to specify the time your program(s)
>>> actually run.  Not some nebulous "daily".  The command you will interface
>>> with is called "crontab".  It deals with files stored (on my system) in
>>> /var/spool/cron.  Some of the important options are:
>>>
>>>    -l   show me my current crontab file (use "> somename" to save a copy)
>>>    -e   put me in my favorite editor to create or modify my crontab file
>>>    -r   remove my crontab file.
>>>
>>> If you do "sudo crontab ..." you will work on root's personal crontab
>>> file.  Or "sudo crontab -u <user> ..." to work on some other users file.
>>>
>>> To be able to use crontab, you either have to "not be denied" or "be
>>> allowed".  Look in /etc/cron.deny and /etc/cron.allow.  Likely the
>>> default is no one listed in cron.deny, so cron.allow doesn't matter
>>> and may not exist.
>>>
>>> Traditional cron files (as opposed to anacron file) have 6 columns, 5 to
>>> specify the execution time(s) and the last for the command.  If you
>>> wanted to run your script at 2:04 AM every day, put this in your crontab.
>>>
>>>      4 2 * * * /home/pereira/bin/backup
>>>
>>> The "*'s" are wildcard for every day of the month, month, and day of the
>>> week.  To create it, just run "crontab -e" add that line to your empty
>>> file and save it.  Crontab will validate the time syntax, save it in
>>> /var/spool/cron/pereira, and register it with cron.
>>>
>>> A couple of caveats that apply to cron and anacron programs.
>>>
>>>    No input from the operator.  Obvious right?
>>>
>>>    NO OUTPUT to the operator.  Even error messages.  Make sure
>>>    everything is redirected to a log file or to /dev/null.
>>>
>>>    No environment assumptions.  Your .bash_profile and .bashrc
>>>    scripts will not have been run.  Unless you set it in your
>>>    script, PATH will be simply /usr/bin:/bin, no /usr/local/bin
>>>    nor ~/bin, nor sbin's.  Unless you do it in the script,
>>>    no environment variables will be set, no aliases nor functions
>>>    will be defined.  Don't make any assumptions.  For important
>>>    scripts, I even use full paths for commands, i.e. "/bin/rm"
>>>    instead of "rm".
>>>
>>> Have fun.
>>>
>>> Jon
>>>> End of included message <<<




More information about the Novalug mailing list