Solved

How to use Cron in Linux

Posted on 2011-02-11
5
531 Views
Last Modified: 2012-05-11
Hi,
I have read quite some bit about Cron and crontab,am new to Linux and am just getting to know some of the utilities.
Can someone  please guide me through some practical Examples of how to use cron.
I need examples i can follow  step by step without having to wonder how or what next to do.I will also appreciate the output to be shown so that as i follow,am able to see how this utility works.
Examples can include but not limited to;
1.how to add a cron job to send a timestamp  to a file
2.how to add a cron job that displays a gui interface
and other examples where  this utility can be applied.

Am running Centos 5 Linux operating system.Your help will be highly appreciated.

Please make your examples clear enough for me to follow;
0
Comment
Question by:protechzm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:Ferrosti
ID: 34869720
Ubuntu Community has a great HowTo that should answer all your questions:
cron howto
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 200 total points
ID: 34869757
Hi,

I assume that you're already familiar with the crontab format, which is this famous

           field         allowed values
           -----         --------------
           minute        0-59
           hour          0-23
           day of month  1-31
           month         1-12 (or names, see below)
           day of week   0-7 (0 or 7 is Sun, or use names)

Open in new window


Further I assume that you're familiar with the crontab command, which must be used to edit your crontab (cronatb -e), to list it (crontab -l) etc.

So your first example could look like this:
Write date/time eyery dav, every hour at 5 min. past the hour in standard format to /tmp/timestamp, appending to that file.

5 * * * * date >> /tmp/timestamp

Your second example cannot be realized, because a cron job is never attached to a terminal, so where should the GUI be displayed? There are possibilities invoving X11 display redirection, but I think that's not what you're after.

Another example - run a backup job, send mail if it fails, nightly at 2:00 A.M. Monday through Friday:

0 2 * * 1-5 /path/to/backup.job >/tmp/backup.log 2>&1 || mail -s "Backup failed" protech@zm.org < /tmp/backup.log

Always use "crontab -e" to open your crontab in an editor (which one depends on the setting of the EDITOR variable), type the lines as shown and save the file using the appropriate editor command.

wmp

0
 
LVL 5

Expert Comment

by:rysic
ID: 34869875
0
 
LVL 1

Accepted Solution

by:
sudhirgoogle earned 300 total points
ID: 34871366
Here is an excellent detail step by step tutorial  on cron with screen shots,

http://www.computernetworkingnotes.com/rhce_certification/cron.htm
0
 

Author Closing Comment

by:protechzm
ID: 34871764
Thanks,this info has really helped
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question