?
Solved

How to use Cron in Linux

Posted on 2011-02-11
5
Medium Priority
?
534 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 800 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 1200 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 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