Results 1 to 8 of 8

Thread: Cron jobs

  1. #1
    Join Date
    Jun 2001
    Posts
    480

    Cron jobs

    Hi guyz I need to set the cron job to run every min. I got a little confused here. Can someone tell me which one is correct.

    */1 * * * * /script path
    or

    */60 * * * * /script path

  2. #2
    Join Date
    Jan 2002
    Location
    Melbourne, AU
    Posts
    740
    Given the choices, neither.

    * * * * * /script path.


    Lats...
    Lats...

  3. #3
    Join Date
    Jun 2001
    Posts
    480
    What about every 10 minutes??

  4. #4
    Join Date
    Jan 2002
    Location
    Melbourne, AU
    Posts
    740
    10 * * * * /script path.


    Lats...
    Lats...

  5. #5
    Join Date
    Jan 2002
    Posts
    73
    .
    Last edited by Josh C.; 09-16-2002 at 04:22 AM.

  6. #6
    Join Date
    Apr 2002
    Location
    Cornfield
    Posts
    131
    Every 10 minutes would be
    */10 * * * * /script
    Fire extinguisher extraordinare
    -------------------------------
    FastServers.Net NOC Admin

  7. #7
    Join Date
    Mar 2002
    Posts
    162
    hi

    this is not mine, i copied sometime ago from somewhere else. It wil explaine evrything. I hope this help evryone.




    regards,
    babak.




    Linux typically provides a user crontab that you may find a better option for your non system crontabs
    If you want to let the users setup/install a crontab for themselves whilst logged in via ssh
    Whats the format for crontab, and what does it all mean?
    How do I ban/stop some users from using crontab?
    Note: crontab scripts (the actual scripts rather than crontab itself), should always be tested in advance of them running live under crontab (IMHO). As they could bring down the machine in the middle of the night when running and you may not be aware for many hours. I think its better to know when awake

    System Schedules /etc/cron.????
    Your scripts (if you want to use this method, should be placed in the relevant directory (or a symbolic link) and the ownership/permissions should also be the same as the others that already exist there.)
    NOTE: That all the cron directories items (see below) are executed in Alphabetical order, so a script called /etc/cron.daily/abc will be executed before /etc/cron.daily/def.
    /etc/cron.daily
    /etc/cron.half-hourly
    /etc/cron.hourly
    /etc/cron.monthly
    /etc/cron.quarter-daily
    /etc/cron.quarter-hourly
    /etc/cron.weekly

    User crontab
    To use the regular crontab system that is available for ALL users.
    IMHO this is a safer way to do things, as the script will be executed as that user and not as the 'root' user.
    This way you can allow your customers to use crontab and limit the damage the scripts can do.
    You can use regular crontab (type "man crontab" or "man cron" in ssh) and use the default editor (=VI), if your a VI lover.
    When the script runs, if it produces any output (STDOUT), this is usually mailed to the user that the script is run under! It would be wise to ensure that this user does actually receive email.
    I prefer to use other editors/ftp with a file containing the crontab listings for each user. Here is a quick/easy way to do this, without altering the raqs default crontab editor (vi):
    Create a file for the user in question (in this example 'username') - have a seperate file for each user is required.
    You may prefer to keep all your crontab files in the respective users home directory... ie /home/sites/home/users/username (dont place them in the users web directory though, because of the potential security risks !!)
    pico -w ~/somefilename
    And add something like this (to add more, just place each one on its OWN line):
    0 11,23 * * * perl /home/sites/home/users/username/the-script.pl
    which tells crontab to run the script at 11:00 & 23:00 every day
    If you want to setup/install a users crontab whilst logged in as root:
    Now you need to update the user ('username' in my example) if you run this as root.
    crontab -u username /home/sites/home/users/username/somefilename
    You can check to see what they user currently has....
    crontab -u username -l
    Or if you want to remove **ALL** the crontab entries for the user ('username' in this example)
    crontab -u username -r
    If you want to let the users setup/install a crontab for themselves whilst logged in via ssh:
    The users crontabs will only be affected here, and not any other users (logged in as username here)
    crontab ~/somefilename
    The user can check to see what they currently have....
    crontab -l
    Or they can remove **ALL** the crontab entries (this does NOT delete the file used above)
    crontab -r

    How to discover all the users that have a crontab setup, and what these crontabs are:
    To see what users have a crontab set to be executed:
    ls -Al /var/spool/cron
    will list all the users whom have a crontab
    To see their crontab, you can see it one of two main ways:
    crontab -u username -l # replace username with the username :-)
    or a less preferred way:
    cat /var/spool/cron/username # replace username with the username :-)

    Whats the format for crontab, and what does it all mean?
    A crontab file consists of six fields, each seperated by a space.
    The first five fields indicate when the script/program/command is to be run. And the sixth field is the script/program/command itself.
    Minutes after the hour (0-59)
    Hour, in 24 hour format (0-23)
    Day of the month (1-31)
    Month (1-12)
    Day of the week (0-6; the 0 refers to Sunday)
    Asterisks "*" specify when commands are to be run in every instance of the value of the field. ie an asterisk in the day field (3) tells crontab to run every day
    Hyphens "-" (inbetween numbers), tells crontab to run this between the start number and end number. ie 5-9 in the month field would tell crontab to run this crontab during May , June, July, August and September (5 - 9 inclusive!).
    Commas "," (inbetween numbers), tells crontab to run this on the specific numbers, which allows mutiple schedules. ie 1,2,3,15,16,17 in the Day of the Month field would tell crontab to run this crontab on the 1st and again on 2nd and again on 3rd and again on 15th and again on 16th and finally on the 17th of the month.
    Mutiple - and , maybe used to further increase the flexibility of crontab. ie 1-5,7,25-38,31 could be used in the day of the Month field.
    Dont forget that a SPACE is the seperator between the 6 above fields, and you should not use it in the first 5 fields!
    Some Examples:
    To run the commands at 5am every day of every month
    0 5 * * * commands
    To run the commands at 10am every Friday of every month
    0 10 * * 5 commands
    To run the commands at 10am every on Sunday and Friday of every month
    0 10 * * 0,5 commands
    To run the commands at 7:09am on weekdays only of every month
    9 7 * * 1-5 commands
    To run the commands between 1:00am and 1:59am at one minute intervals on every day of the month
    * 1 * * * commands
    To run the commands at 1pm on the 5th, 10th, 15th, 20th, 25th, and 30th only of every month (obviously February does not use the one schedule on the 30th)
    0 13 5,10,15,20,25,30 * * commands
    To run the commands every other month at 9pm
    0 21 * 1,3,5,7,9,11 * commands

    How do I ban/stop some users from using crontab?
    To ban/stop a user from updating/deleting/creating a crontab, you will need to create a file in /etc/ called cron.deny, and ensure the permissions are set to 0600 and is owned by root:
    touch /etc/cron.deny
    chmod 0600 /etc/cron.deny
    chown root.root /etc/cron.deny
    In this /etc/cron.deny file you should place a list of ALL users you want banned (each on a new line works fine)
    Should a user then attempt to use crontab when banned, they would see a message along these lines:
    You (username) are not allowed to use this program (crontab)
    See crontab(1) for more information

  8. #8
    Join Date
    Sep 2002
    Posts
    57
    This was a good information by you babak.

Posting Permissions

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