Swimminginthought

A place for all things technical and my mind..

Menu
  • About Me / Hire Me
Menu

How to use Cron. The linux / unix Scheduler

Posted on March 25, 2012 by Percy Kwong

Cron as it is called is a very powerful tool.  It’s simply a scheduler that allows you to do a multitude of tasks at any given time.  It’s been around since the beginning of time and is built into every linux, unix, bsd distribution out there.  Even Microsoft has a version of Cron, albeit it’s harder to use.

This is a super simple, completely high level cron overview.  It can do a lot, but I’m going to cover the basics so you can at least get going.

1. Every user has his/her own cron file.  This is called a crontab.

2. To access and modify your crontab, log in as the user whos crontab you want to modify and simply type ‘crontab -e’

3. The user’s crontab may be empty, it may have things in it, etc.  Here you get to modify it .  Crontab uses vi as it’s editor.  So you’ll need to learn a thing or two about vi.  There’s a tutorial on basic vi on this blog.

 

So you typed it in and now you see either a blank screen in vi or you see something that might look like this:

0 2 * * 5 /root/scripts/swimminginthought.backup.s3 >> /dev/null &
0 2 * * * /root/scripts/database.dump.s3 >> /dev/null &

Looks like greek right?  Well, it’s not.  In fact, it couldn’t be any simpler.  So here’s the explanation.

There are 6 fields in a crontab.  From left to right, it goes like this.

Fields, (left to right):   minute,hour,day,month,day of the week [0-6]  0 being Sunday and 6 being Saturday, path to script or command you want to execute.

* in any of the first five fields means execute every interval (depending on the field)

so if you wanted to execute a task every minute, just simply make an entry that looks like this:

* * * * * /your.script

if you wanted to execute something at 2am every day, here’s your entry

0 2 * * * /your.script

if you wanted to execute something at 2am every friday, it would be:

0 2 * * 5 /your.script

If you wanted to execute something every 2 hours on friday, the example would be:

0 */2 * * * /your.script

Pretty simple, huh?

one cron entry per line.  That’s all you need to know.  Once you’re done with your scripts, just save and close the file and you’re ready to go!  The cron jobs are active.

**TEST YOUR SCRIPTS BEFORE PUTTING INTO CRONTAB.***

If you’re having trouble with cron, I can do this for you or walk you through for a small donation (assuming you already have your scripts written and tested.)     Just contact me.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs
  • Resurrection of the Blog
  • Encryption type Matters with Deep Packet Inspection – solved
  • Completely off topic.. Just a personal note.

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs

Recent Comments

  • Percy Kwong on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Nick Doelman on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Percy Kwong on International Text solutions – A solution
  • Muzahid Ul Islam on The Browser Wars; Which One is Best?
  • Muzahid Ul Islam on International Text solutions – A solution

Archives

  • September 2019
  • August 2019
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • August 2011
  • June 2011
  • March 2011
  • February 2011
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • January 2010
  • November 2009
  • October 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008

Categories

  • Activism
  • All
  • Amazon S3
  • Announcements
  • Apache
  • Apple
  • Applications
  • Automation
  • AWS
  • Azure
  • Backups
  • Blogging
  • Books
  • Bootcamp
  • CentOS – RHEL
  • Cloud Computing
  • Cloudformation
  • Consulting Advice
  • Craigslist
  • Databases
  • Deep Packet Inspection
  • Doing the right thing
  • e-Book Readers
  • E-Mail
  • EC2
  • energy-efficiency
  • environment
  • Expose
  • firewalls
  • General Observations
  • Hardware
  • Hope
  • Hosting
  • IaC
  • Important things to do in life
  • Infrastructure as Code
  • Kubernetes
  • Linux
  • Media and Encoding
  • Miscellany
  • Mobile Phones
  • MySql
  • Networking
  • Performance
  • Personal
  • pfsense
  • Politics
  • Privacy
  • Redundancy
  • Routers
  • security
  • SPAM
  • Tech that doesn't work like it should
  • Tips and Tricks
  • Tools that work
  • Tout
  • Video
  • Virtual Computing
  • VOIP-Voice Over IP
  • VPN
  • Web Browsers
  • Web Hosting
  • Websites
  • Windows
  • Wordpress

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2026 Swimminginthought | Built using WordPress and Responsive Blogily theme by Superb