<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Michael Helm&#039;s Technology Blog &#187; vi</title>
	<atom:link href="http://www.ihelm.org.uk/tag/vi/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ihelm.org.uk</link>
	<description>Linux Servers, Cpanel and Mysql along with my own tech thoughts</description>
	<lastBuildDate>Thu, 29 Sep 2011 22:19:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to use crontab to schedule tasks in Linux</title>
		<link>http://www.ihelm.org.uk/2009/07/how-to-use-crontab-to-schedule-tasks-in-linux/</link>
		<comments>http://www.ihelm.org.uk/2009/07/how-to-use-crontab-to-schedule-tasks-in-linux/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 20:15:50 +0000</pubDate>
		<dc:creator>mhelm</dc:creator>
				<category><![CDATA[Server]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[vi]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.ihelm.org.uk/?p=79</guid>
		<description><![CDATA[Another of the most useful tools in server administration is the Crontab &#8211; you use this to schedule jobs (programs) to run at regular intervals. These tasks can be  varied, from restarting servers, services &#8211; creating files, changing permissions, runing batch programs, deleting files etc&#8230; Of course sometimes crontab is not the best solution as [...]]]></description>
			<content:encoded><![CDATA[<p>Another of the most useful tools in server administration is the Crontab &#8211; you use this to schedule jobs (programs) to run at regular intervals.</p>
<p>These tasks can be  varied, from restarting servers, services &#8211; creating files, changing permissions, runing batch programs, deleting files etc&#8230;</p>
<p>Of course sometimes crontab is not the best solution as it can have several problems &#8211; in which case other choices are available &#8211; including writing your own &#8211; however we will cover that another time.</p>
<p>First a coouple of facts about cron:</p>
<ol>
<li>Cron has evolved a bit since inception but the basic principles are the same &#8211; old server admins are as good as new ones with this tool!</li>
<li>Cron will run new jobs at most once a minute &#8211; that&#8217;s the smallest resolution you can have.</li>
<li>Old systems used to wake up every minute and check for new work &#8211; the same as a simple replacement service might do &#8211; however this didn&#8217;t scale well when cpu power was low but users high on old mainframe systems &#8211; new systems still only execute once a minute.</li>
<li>the cron service loads up any relavent cron files (which exist in users home directories or in /etc/cron.d/) and saves the information so it only needs to run when there is really jobs to run &#8211; when you edit the crontab it reloads it&#8217;s list so it doesn&#8217;t need to keep checking for changes &#8211; it&#8217;s important to edit it right!</li>
<li>Even if a previous program hasn&#8217;t finished &#8211; cron can run it again or run more jobs &#8211; this can bring down badly configured systems! so be careful how you use it.</li>
</ol>
<p>Generally to edit the crontab &#8211; which is where you would add things to run type in &#8220;crontab -e&#8221; &#8211; this will open it in your system editor (vim is my choice, but others can be used).</p>
<p>you will probably see some content &#8211; similar to this:</p>
<pre>
</pre>
<pre style="color: black; background-color: #f9f9f9; line-height: 1.1em; padding: 1em; border: 1px dashed #2f6fab;">1 0 * * *  shutdown -r now</pre>
<p>This means that at one minute past midnight the server will reboot (execture the immediate shutdown and restart command with no delay) each day.  The * are wildcards saying that the instruction should run no matter the criteria of that column (if it&#8217;s all * then it will run each minute).</p>
<p>The fields are the following:   I recommend pasting this in the top of your crontab file &#8211; the # at the start mean it will ignore the entries.</p>
<pre>
</pre>
<pre style="color: black; background-color: #f9f9f9; line-height: 1.1em; padding: 1em; border: 1px dashed #2f6fab;"># .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *</pre>
<p>Remember if the program has output you can store it in a file the same as you can on the command line &#8211; just type &#8221; &gt; /var/log/logfile&#8221;</p>
<p>in the entry after the command and it will log output to the file in question.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ihelm.org.uk/2009/07/how-to-use-crontab-to-schedule-tasks-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

