Solved

How to use Cron in Linux

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

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

895 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

12 Experts available now in Live!

Get 1:1 Help Now