Find the answer to your Linux question:
Results 1 to 9 of 9
Hi all, I have a Fedora 11 box and I am confused about cron, where exactly do I enter the cron jobs? For example, I have a job that needs ...
  1. #1
    Just Joined!
    Join Date
    Jun 2005
    Posts
    13

    cron

    Hi all,

    I have a Fedora 11 box and I am confused about cron, where exactly do I enter the cron jobs?

    For example, I have a job that needs to run every half hour.

    Thanks

    Max

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    See the crontab command. Here is the manpage:
    Code:
    CRONTAB(1)                                                          CRONTAB(1)
    
    NAME
           crontab - maintain crontab files for individual users (ISC Cron V4.1)
    
    SYNOPSIS
           crontab [-u user] file
           crontab [-u user] [-l | -r | -e] [-i] [-s]
    
    DESCRIPTION
           Crontab is the program used to install, deinstall or list the tables used to drive the cron(8) daemon
           in ISC Cron.  Each user can have their own crontab, and though these are files in /var/spool/ ,  they
           are  not intended to be edited directly. For SELinux in mls mode can be even more crontabs - for each
           range. For more see selinux(8).
    
           If the cron.allow file exists, then you must be listed therein in order to be  allowed  to  use  this
           command.   If the cron.allow file does not exist but the cron.deny file does exist, then you must not
           be listed in the cron.deny file in order to use this command.  If neither of these files exists, only
           the super user will be allowed to use this command.
    
    OPTIONS
           -u     It  specifies  the  name  of  the  user whose crontab is to be tweaked.  If this option is not
                  given, crontab examines "your" crontab, i.e., the crontab of the person executing the command.
                  Note  that  su(8)  can  confuse crontab and that if you are running inside of su(8) you should
                  always use the -u option for safety’s sake.  The first form of this command is used to install
                  a new crontab from some named file or standard input if the pseudo-filename "-" is given.
    
           -l     The current crontab will be displayed on standard output.
    
           -r     The current crontab will be be removed.
    
           -e     This  option  is  used to edit the current crontab using the editor specified by the VISUAL or
                  EDITOR environment variables.  After you exit from the editor, the modified  crontab  will  be
                  installed automatically.
    
           -i     This  option  modifies  the  -r option to prompt the user for a ’y/Y’ response before actually
                  removing the crontab.
    
           -s     It will append the current SELinux security context string as  an  MLS_LEVEL  setting  to  the
                  crontab  file  before  editing  /  replacement  occurs - see the documentation of MLS_LEVEL in
                  crontab(5).
    
    SEE ALSO
           crontab(5), cron(8)
    
    FILES
           /etc/cron.allow
           /etc/cron.deny
    
    STANDARDS
           The crontab command conforms to IEEE Std1003.2-1992 (‘‘POSIX’’).  This  new  command  syntax  differs
           from previous versions of Vixie Cron, as well as from the classic SVR3 syntax.
    
    DIAGNOSTICS
           A fairly informative usage message appears if you run it with a bad command line.
    
    AUTHOR
           Paul Vixie <vixie@isc.org>
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jan 2010
    Posts
    35
    You really should avoid editing the file directly and instead use the crontab command. It will verify things are being entered properly.

  4. #4
    Just Joined!
    Join Date
    Mar 2010
    Location
    Grand Rapids, MI
    Posts
    15
    Not exactly sure about fedora 11, but with Redhat ES 4.5-5.x there are a couple of ways to enter a cron job depending on which RPM's are installed (anacron, vixie-cron) and how often you want the job to run.

    It's a bit frustrating, as different RPM packages will choose different methods for adding cron jobs, making you search to see where a process is being called. Anyways...

    For a 5 min interval, you can:
    - Add the job file to /etc/cron.d
    - Add the entry to the users cron file : /var/spool/cron/crontabs/$user$ (not recommended, but still done fairly often).
    - Use the crontab command as described earlier
    - Add an entry to /etc/crontab

  5. #5
    Just Joined! fatra2's Avatar
    Join Date
    Mar 2005
    Location
    Switzerland
    Posts
    32
    Hi there,

    A cron entry for your purpose is quite simple. If you want your job to run every half hour, you could do something like this:

    0,30 * * * * /usr/bin/theProg differentOptionsw whatNext
    or
    15,45 * * * * /usr/bin/theProg differentOptionsw whatNext

    "theProg" will run every half hour. You need to know that if your computer is not running, cron will not look back in the past.

    Cheers

  6. #6
    vkv
    vkv is offline
    Just Joined!
    Join Date
    Apr 2010
    Posts
    29
    Create a file

    touch file

    edit that file and add the schedule and save the file

    Then user crontab command

    crontab file

    or crontab -u username file (Cron job for particular user)

    This should work

  7. #7
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    What's wrong with using crontab -e? And crontab -l to view the jobs that are setup?

  8. #8
    vkv
    vkv is offline
    Just Joined!
    Join Date
    Apr 2010
    Posts
    29
    Yeah that also works.

    I was just explaining one method.

    crontab -e and crontab -l works great

  9. #9
    Just Joined! fatra2's Avatar
    Join Date
    Mar 2005
    Location
    Switzerland
    Posts
    32
    Hi there,

    Quote Originally Posted by scm View Post
    What's wrong with using crontab -e? And crontab -l to view the jobs that are setup?
    You are absolutely right. crontab -e will let you directly edit the crontab file. But, with this command, you enter the vim text editor. If you don't know it, or don't feel comfortable with it, you are better of with something else.

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...