<?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>gHacks technology news &#187; cron job</title>
	<atom:link href="http://www.ghacks.net/tag/cron-job/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ghacks.net</link>
	<description>A technology blog covering software, mobile phones, gadgets, security, the Internet and other relevant areas.</description>
	<lastBuildDate>Mon, 23 Nov 2009 22:22:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Backup MySQL Databases In Linux Regularly</title>
		<link>http://www.ghacks.net/2009/01/12/backup-mysql-databases-in-linux-regularly/</link>
		<comments>http://www.ghacks.net/2009/01/12/backup-mysql-databases-in-linux-regularly/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 00:08:19 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials Basic]]></category>
		<category><![CDATA[backup database]]></category>
		<category><![CDATA[backup mysql]]></category>
		<category><![CDATA[cron job]]></category>
		<category><![CDATA[cron tab]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[linux tutorial]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql database]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=9829</guid>
		<description><![CDATA[The post Using Cron to Automate Linux Tasks by Jack got me thinking that some users might be interested in a practical example. The following tutorial will explain how to setup a small script to backup MySQL databases on a Linux server which will be run daily using a cron job. The best way to [...]]]></description>
			<content:encoded><![CDATA[<p>The post <a href="http://www.ghacks.net/2009/01/11/using-cron-to-automate-linux-tasks/">Using Cron to Automate Linux Tasks</a> by Jack got me thinking that some users might be interested in a practical example. The following tutorial will explain how to setup a small script to backup MySQL databases on a Linux server which will be run daily using a cron job. The best way to start would be to read up on the introduction by Jack about Cron so that you got a understanding of the basics.</p>
<p>We start by creating the bash script first and continue with the cron job after the bash script has been tested to work as intended. All commands in the following paragraphs are executed from the command line.</p>
<p><span id="more-9829"></span><code>vi backup.sh</code></p>
<p>This will create an empty text file in the vi editor. This will be the script that will be executed by the cron job on a daily basis.</p>
<p><code>bin/sh<br />
/usr/bin/mysqldump -A -u [Username] -p[Password] | gzip > /backups/mysqldump`date +%m_%d_%y`.gz<br />
</code></p>
<p>Press <strong>i</strong> to enter insert mode and copy and paste the two lines above in the editor. What the script does is to use the mysqldump function to create a mysql backup and store it gzipped in the backups directory using mysqldumpDate.gz as the name with data being the day the backup was created.</p>
<p>The two variables [Username] and [Password] have to be edited and the username and password of a user with sufficient rights entered. It might also be necessary to change the location of the backup folder.</p>
<p>Press <strong>ESC</strong> to enter command mode and <strong>:x</strong> to save the file.</p>
<p><code>./backup.sh</code></p>
<p>Execute the script to see if it is working correctly. It should create the dump of the MySQL database in the defined directory. It might be necessary to change the permission level of the backup.sh file if you get a permission error during execution.</p>
<p><code>chmod 755 backup.sh</code></p>
<p>If the script is working as intended it can be added as a cron job. The following command will open the user crontab list.</p>
<p><code>crontab -e</code></p>
<p>If you are in the vi editor you press i to enter insert mode again and add the following line</p>
<p><code>0 7 * * * /path/to/backup.sh</code></p>
<p>Please refer to the tutorial for a detailed instruction on how to set the cron job up to suite your needs. This one will execute the script every day on 7am.</p>
<p>It is a good idea to check back after the next execution to verify that everything is working as intended.</p>

	Tags: <a href="http://www.ghacks.net/tag/backup-database/" title="backup database" rel="tag">backup database</a>, <a href="http://www.ghacks.net/tag/backup-mysql/" title="backup mysql" rel="tag">backup mysql</a>, <a href="http://www.ghacks.net/tag/cron-job/" title="cron job" rel="tag">cron job</a>, <a href="http://www.ghacks.net/tag/cron-tab/" title="cron tab" rel="tag">cron tab</a>, <a href="http://www.ghacks.net/tag/database/" title="database" rel="tag">database</a>, <a href="http://www.ghacks.net/tag/linux/" title="Linux" rel="tag">Linux</a>, <a href="http://www.ghacks.net/tag/linux-tutorial/" title="linux tutorial" rel="tag">linux tutorial</a>, <a href="http://www.ghacks.net/tag/mysql/" title="mysql" rel="tag">mysql</a>, <a href="http://www.ghacks.net/tag/mysql-database/" title="mysql database" rel="tag">mysql database</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/04/09/set-up-mysql-database-replication/" title="Set up MySQL database replication (April 9, 2009)">Set up MySQL database replication</a> (1)</li>
	<li><a href="http://www.ghacks.net/2008/12/20/install-phpmyadmin-for-easy-mysql-administration/" title="Install phpmyadmin for easy MySQL administration (December 20, 2008)">Install phpmyadmin for easy MySQL administration</a> (6)</li>
	<li><a href="http://www.ghacks.net/2009/07/30/database-monitoring-software-db2rss/" title="Database Monitoring Software Db2rss (July 30, 2009)">Database Monitoring Software Db2rss</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/01/11/using-cron-to-automate-linux-tasks/" title="Using Cron to Automate Linux Tasks (January 11, 2009)">Using Cron to Automate Linux Tasks</a> (7)</li>
	<li><a href="http://www.ghacks.net/2008/11/05/have-wordpress-back-ups-emailed/" title="Have WordPress back-ups emailed (November 5, 2008)">Have WordPress back-ups emailed</a> (3)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/01/12/backup-mysql-databases-in-linux-regularly/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Using Cron to Automate Linux Tasks</title>
		<link>http://www.ghacks.net/2009/01/11/using-cron-to-automate-linux-tasks/</link>
		<comments>http://www.ghacks.net/2009/01/11/using-cron-to-automate-linux-tasks/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 21:32:12 +0000</pubDate>
		<dc:creator>Jack Wallen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tutorials Advanced]]></category>
		<category><![CDATA[Tutorials Basic]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[automated tasks]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[cron job]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[script automation]]></category>
		<category><![CDATA[vi]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=9823</guid>
		<description><![CDATA[Linux is one of the most flexible and useful operating systems available. One of the tools that places Linux at the top of the flexibility and usability scale is cron. The cron system allows you to automate tasks without the aid of third party software. But because few know how to use cron, it seems [...]]]></description>
			<content:encoded><![CDATA[<p>Linux is one of the most flexible and useful operating systems available. One of the tools that places Linux at the top of the flexibility and usability scale is cron. The cron system allows you to automate tasks without the aid of third party software. But because few know how to use cron, it seems too complex to bother with. Not so. The cron system is actually quite easy to use. Let&#8217;s take a look at cron.</p>
<p>The cron system works by reading various crontab files either found in a users&#8217; directory or within the <strong>/etc </strong>directory. These cron files can be edited with either the <em>crontab</em> command or by editing the various files within <strong>/etc</strong>. Only the root user can edit the <strong>/etc</strong> files because those files (found in the subdirectories <strong>/etc/cron.d, /etc/cron.daily, /etc/cron.hourly, /etc/cron.weekly, /etc/cron.monthly</strong>) are used for system services.  Instead of focusing on system services, I will illustrate how to automate the execution of a user-created bash script.</p>
<p><span id="more-9823"></span>This imaginary bash script will be called <em>myscript.sh</em>. This script will be housed in <strong>/home/jlwallen/ </strong>and will have executable permission (by way of <em>chmod u+x myscript.sh</em>).  What we want to do is automate the execution of this script so that it executes once per day at the same time every day (we&#8217;ll say 7am).</p>
<p>Before we get into editing with crontab we first need to chat about how cron views time.The cron system looks at time like this:</p>
<ul>
<li><em>Minute(0-59)</em></li>
<li><em>Hour (0-23)</em></li>
<li><em>Day of the month (1-31)</em></li>
<li><em>Month (1-12)</em></li>
<li><em>Day of the week (0-6 with Sunday being 0)</em></li>
</ul>
<p>The structure of cron time looks like this:</p>
<p>Minute Hour Day of month Month Day of the week</p>
<p>The trick for cron is that when you do not have an entry for a section you add an &#8220;*&#8221;. So the time entry for a cron job that should run at 7am every day of the week would look like:</p>
<p><em>0 7 * * * </em></p>
<p>That is not the complete cron entry, just the time portion. Now, on to editing with crontab.</p>
<p><strong>Crontab</strong></p>
<p>Users edit their cron entries with the <em>crontab</em> command. The crontab command has a few switches:</p>
<ul>
<li>e &#8211; Edit your crontab</li>
<li>l &#8211; List your crontab</li>
<li>r &#8211; Delete all crontab entries</li>
</ul>
<p>To add a new crontab entry enter the command <em>crontab -e</em> which will place you in the vi text editor with your user crontab file opened. If you&#8217;re not familiar with vi I&#8217;ll give you the crash course as we edit the crontab.</p>
<p>First click the &#8220;i&#8221; key to go into the insert mode. You can now add text. Enter the cron entry to run the myscript.sh every day at 7am. This entry will look like:</p>
<p>* 7 * * * ~/myscript.sh</p>
<p>Now hit the Esc key to get out of the insert mode. Once out of insert mode you need to write the file and quite crontab. To do this hit the &#8220;:&#8221; key followed by &#8220;wq&#8221; (for write and quite). Finish the job by hitting the Enter key.</p>
<p>You should see &#8220;crontab: installing new crontab&#8221; at your bash prompt.</p>
<p>Congratulations, you&#8217;ve just created your first cron job!</p>

	Tags: <a href="http://www.ghacks.net/tag/automated-tasks/" title="automated tasks" rel="tag">automated tasks</a>, <a href="http://www.ghacks.net/tag/cron/" title="cron" rel="tag">cron</a>, <a href="http://www.ghacks.net/tag/cron-job/" title="cron job" rel="tag">cron job</a>, <a href="http://www.ghacks.net/tag/crontab/" title="crontab" rel="tag">crontab</a>, <a href="http://www.ghacks.net/tag/linux/" title="Linux" rel="tag">Linux</a>, <a href="http://www.ghacks.net/tag/script-automation/" title="script automation" rel="tag">script automation</a>, <a href="http://www.ghacks.net/tag/vi/" title="vi" rel="tag">vi</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/01/12/backup-mysql-databases-in-linux-regularly/" title="Backup MySQL Databases In Linux Regularly (January 12, 2009)">Backup MySQL Databases In Linux Regularly</a> (11)</li>
	<li><a href="http://www.ghacks.net/2009/01/22/back-up-your-apache-web-directory-and-database-with-this-simple-script/" title="Back up your Apache web directory and database with this simple script (January 22, 2009)">Back up your Apache web directory and database with this simple script</a> (0)</li>
	<li><a href="http://www.ghacks.net/2008/02/07/yoggie-pico-personal-mobile-security-computer/" title="Yoggie PICO Personal Mobile Security Computer (February 7, 2008)">Yoggie PICO Personal Mobile Security Computer</a> (3)</li>
	<li><a href="http://www.ghacks.net/2009/10/30/with-ubuntu-9-10-arrives-wubi-9-10/" title="With Ubuntu 9.10 Arrives Wubi 9.10 (October 30, 2009)">With Ubuntu 9.10 Arrives Wubi 9.10</a> (2)</li>
	<li><a href="http://www.ghacks.net/2006/12/07/widgets-for-linux-superkaramba/" title="Widgets for Linux: SuperKaramba (December 7, 2006)">Widgets for Linux: SuperKaramba</a> (6)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/01/11/using-cron-to-automate-linux-tasks/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
