<?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>LogikDevelopment &#187; cron</title>
	<atom:link href="http://www.logikdev.com/tag/cron/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.logikdev.com</link>
	<description>&#34;Il n&#039;y a pas de problème, il n&#039;y a que des solutions. L&#039;esprit de l&#039;homme invente ensuite le problème.&#34; André Gide</description>
	<lastBuildDate>Fri, 27 Aug 2010 08:54:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using the &#8216;date&#8217; command in your crontab</title>
		<link>http://www.logikdev.com/2010/05/25/using-the-date-command-in-your-crontab/</link>
		<comments>http://www.logikdev.com/2010/05/25/using-the-date-command-in-your-crontab/#comments</comments>
		<pubDate>Tue, 25 May 2010 18:15:42 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[date command]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=550</guid>
		<description><![CDATA[Crontab, as most people know, enables users to schedule commands or shell scripts to run periodically at certain times or dates. The other day, this very useful Linux tool gave me a hard time! Indeed, one of my commands wasn&#8217;t working in cron but was working perfectly fine when written in a shell console. The [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Crontab</strong>, as most people know, enables users to schedule commands or shell scripts to run periodically at certain times or dates.</p>
<p>The other day, this very useful Linux tool gave me a hard time! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
Indeed, one of my commands wasn&#8217;t working in cron but was working perfectly fine when written in a shell console.</p>
<p>The faulty command looked like this:</p>
<pre class="brush: bash; light: true;">
0 5 * * 3 /data/script.sh &gt; /data/script_`date +%y%m%d`.log 2&gt;&amp;1
</pre>
<p>If I run this command in a shell console, everything works fine and I get a log file containing today&#8217;s date in its filename. However, if I set this command line in my crontab, it doesn&#8217;t work and no log file is even created!</p>
<p>Reading the documentation of cron, I discovered the following statement:</p>
<blockquote><p>Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.</p></blockquote>
<p>Well, this is good to know, isn&#8217;t it? <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
We need to escape the percent-signs on our command line.</p>
<p>So in order to get our &#8216;faulty&#8217; command to run in cron, it needs to look like the following:</p>
<pre class="brush: bash; light: true;">
0 5 * * 3 /data/script.sh &gt; /data/script_`date +\%y\%m\%d`.log 2&gt;&amp;1
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/05/25/using-the-date-command-in-your-crontab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Locale settings for your cron job</title>
		<link>http://www.logikdev.com/2010/02/02/locale-settings-for-your-cron-job/</link>
		<comments>http://www.logikdev.com/2010/02/02/locale-settings-for-your-cron-job/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 22:55:35 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[locale]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[UTF-8]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=291</guid>
		<description><![CDATA[Do you get special characters problem when executing your bash script from a cron job? And does the same script work fine when it is directly executed from the command line? If yes, continue reading this article! The reason of this characters problem is probably because of your locale settings. Indeed, If you try to [...]]]></description>
			<content:encoded><![CDATA[<p>Do you get special characters problem when executing your bash script from a cron job?<br />
And does the same script work fine when it is directly executed from the command line?<br />
If yes, continue reading this article! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The reason of this characters problem is probably because of your locale settings.<br />
Indeed, If you try to run the command <code>locale</code> from the command line and from a cron job, you may get different results such as:</p>
<table style="width: 100%; border:0px;">
<tbody>
<tr>
<td style="width:50%; border:0px;">From the command line</td>
<td style="width:50%; border:0px;">From a cron job</td>
</tr>
<tr>
<td style="border:0px;">
<pre class="brush: bash; light: true;">
LANG=en_US.UTF-8
LC_CTYPE=&quot;en_US.UTF-8&quot;
LC_NUMERIC=&quot;en_US.UTF-8&quot;
LC_TIME=&quot;en_US.UTF-8&quot;
LC_COLLATE=&quot;en_US.UTF-8&quot;
LC_MONETARY=&quot;en_US.UTF-8&quot;
LC_MESSAGES=&quot;en_US.UTF-8&quot;
LC_PAPER=&quot;en_US.UTF-8&quot;
LC_NAME=&quot;en_US.UTF-8&quot;
LC_ADDRESS=&quot;en_US.UTF-8&quot;
LC_TELEPHONE=&quot;en_US.UTF-8&quot;
LC_MEASUREMENT=&quot;en_US.UTF-8&quot;
LC_IDENTIFICATION=&quot;en_US.UTF-8&quot;
LC_ALL=
</pre>
</td>
<td style="border:0px;">
<pre class="brush: bash; light: true;">
LANG=
LC_CTYPE=&quot;POSIX&quot;
LC_NUMERIC=&quot;POSIX&quot;
LC_TIME=&quot;POSIX&quot;
LC_COLLATE=&quot;POSIX&quot;
LC_MONETARY=&quot;POSIX&quot;
LC_MESSAGES=&quot;POSIX&quot;
LC_PAPER=&quot;POSIX&quot;
LC_NAME=&quot;POSIX&quot;
LC_ADDRESS=&quot;POSIX&quot;
LC_TELEPHONE=&quot;POSIX&quot;
LC_MEASUREMENT=&quot;POSIX&quot;
LC_IDENTIFICATION=&quot;POSIX&quot;
LC_ALL=
</pre>
</td>
</tr>
</tbody>
</table>
<p>As you can see, the cron job is not using UTF-8. That must be the problem! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><br/>So the question now is how to change the locale settings for the cron job?<br />
Some people say that you need to add the following environment variables to the crontab entry:</p>
<pre class="brush: bash; light: true;">
SHELL=/bin/bash
LANG=en_US.UTF-8
LANGUAGE=en
LC_CTYPE=en_US.UTF-8
</pre>
<p>But this actually didn&#8217;t work for me. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p><br/>What you can do instead is create (if not already present) the file <code>/etc/environment</code> and add the following line:</p>
<pre class="brush: bash; light: true;">
LANG=en_US.UTF-8
</pre>
<p>The cron process will read this file when it starts, so you need to restart it in order to apply the change:</p>
<pre class="brush: bash; light: true;">
service cron restart
</pre>
<p><br/>Hope this will fix your characters problem. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2010/02/02/locale-settings-for-your-cron-job/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
