Solved

How to use Cron in Linux

Posted on 2011-02-11
5
519 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now