Solved

How to use Cron in Linux

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internal CA server 6 93
WordPress: Debugging from my Windows 10 Desktop 6 65
rsyslog raw message 4 37
AWS Linux EC2 question on group 7 22
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
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.:

733 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