<?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; shell</title>
	<atom:link href="http://www.logikdev.com/tag/shell/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>Tue, 20 Dec 2011 12:25:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>S3 command failed if the time is not synced</title>
		<link>http://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=s3-command-failed-if-time-not-synced</link>
		<comments>http://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 23:11:43 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ntpdate]]></category>
		<category><![CDATA[s3sync]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[system date]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1610</guid>
		<description><![CDATA[This is already the second post about the s3sync ruby program. The first article was focused on monitoring s3sync with Zabbix. I will talk on this one about an error I got when running the S3 synchronisation: S3 command failed: list_bucket prefix /data max-keys 200 delimiter / With result 403 Forbidden S3 ERROR: # s3sync.rb:290:in [...]]]></description>
			<content:encoded><![CDATA[<p>This is already the second post about the <a href="https://forums.aws.amazon.com/thread.jspa?threadID=11975&amp;start=0&amp;tstart=0" target="_blank"><strong>s3sync</strong></a> ruby program. The first article was focused on <a title="Monitor s3sync with Zabbix" href="http://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/">monitoring s3sync with Zabbix</a>.</p>
<p>I will talk on this one about an error I got when running the S3 synchronisation:</p>
<pre>
S3 command failed:
list_bucket prefix /data max-keys 200 delimiter /
With result 403 Forbidden
S3 ERROR: #
s3sync.rb:290:in `+': can't convert nil into Array (TypeError)
	from s3sync.rb:290:in `s3TreeRecurse'
	from s3sync.rb:346:in `main'
	from ./thread_generator.rb:79:in `call'
	from ./thread_generator.rb:79:in `initialize'
	from ./thread_generator.rb:76:in `new'
	from ./thread_generator.rb:76:in `initialize'
	from s3sync.rb:267:in `new'
	from s3sync.rb:267:in `main'
	from s3sync.rb:735
</pre>
<p>As you can see, this error is not very human-friendly! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_surprised.gif' alt=':-o' class='wp-smiley' />  The only thing we know is that the S3 command failed because of the error <code>can't convert nil into Array</code>. It looks to me like an internal error within s3sync&#8230;</p>
<p>But after some investigation, it appears it is simply because the system date on the server is not correct. I cannot tell you how much time I spent on this one!  <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' /> </p>
<p>Anyway, if you are doing automatic backups as describe on <a href="http://blog.eberly.org/2006/10/09/how-automate-your-backup-to-amazon-s3-using-s3sync/" target="_blank">John Eberly&#8217;s blog</a>, you need to add the following code at the top of your <code>upload.sh</code> script:</p>
<pre class="brush: bash; title: ; notranslate">
# update the system date
/usr/sbin/ntpdate 3.uk.pool.ntp.org 2.uk.pool.ntp.org 1.uk.pool.ntp.org 0.uk.pool.ntp.org
</pre>
<p><br/><strong>NB:</strong> please find below the command lines I use to install <a href="http://www.eecis.udel.edu/~mills/ntp/html/ntpdate.html" target="_blank"><strong>ntpdate</strong></a> on a Debian server:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
apt-get install ntpdate
dpkg-reconfigure tzdata
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Monitor s3sync with Zabbix</title>
		<link>http://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitor-s3sync-with-zabbix</link>
		<comments>http://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 22:28:53 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[s3sync]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[synchronisation]]></category>
		<category><![CDATA[Zabbix]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1566</guid>
		<description><![CDATA[s3sync is a ruby program that easily transfers directories between a local directory and an S3 bucket:prefix. It behaves somewhat, but not precisely, like the rsync program. I am using this tool to automatically backup the important data from Debian servers to Amazon S3. I am not going to explain here how to install s3sync [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://forums.aws.amazon.com/thread.jspa?threadID=11975&#038;start=0&#038;tstart=0" target="_blank"><strong>s3sync</strong></a> is a ruby program that easily transfers directories between a local directory and an S3 bucket:prefix. It behaves somewhat, but not precisely, like the <strong>rsync</strong> program.</p>
<p>I am using this tool to automatically backup the important data from Debian servers to Amazon S3. I am not going to explain here how to install s3sync as it is not the purpose of this article. However, you can read this very useful article from John Eberly&#8217;s blog: <a href="http://blog.eberly.org/2006/10/09/how-automate-your-backup-to-amazon-s3-using-s3sync/" target="_blank">How I automated my backups to Amazon S3 using s3sync</a>.</p>
<p>If you followed the steps from John Eberly&#8217;s post, you should have an <code>upload.sh</code> script and a crontab job which executes this script periodically.</p>
<p>From this point, here is what you need to do to monitor the success of the synchronisation with <a href="http://www.zabbix.com/" target="_blank"><strong>Zabbix</strong></a>:</p>
<ol>
<li>Add the following code at the end of your <code>upload.sh</code> script:
<pre class="brush: bash; title: ; notranslate">
# print the exit code
RETVAL=$?
[ $RETVAL -eq 0 ] &amp;&amp; echo &quot;Synchronization succeed&quot;
[ $RETVAL -ne 0 ] &amp;&amp; echo &quot;Synchronization failed&quot;
</pre>
</li>
<li>Log the output of the cron script as follow:
<pre class="brush: bash; light: true; title: ; notranslate">
30 2 * * sun /path/to/upload.sh &gt; /var/log/s3sync.log 2&gt;&amp;1
</pre>
</li>
<li>On Zabbix, create a new item which will check the existence of the sentence &#8220;Synchronization failed&#8221; in the file <code>/var/log/s3sync.log</code>:<br />
<a href="http://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_item.png" rel="lightbox[1566]"><img src="http://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_item-297x300.png" alt="" title="Create a new item on Zabbix to monitor s3sync" width="297" height="300" class="aligncenter size-medium wp-image-1569" /></a><br />
Item key: <code>vfs.file.regmatch[/var/log/s3sync.log,Synchronization failed]</code><br />
<br/>
</li>
<li>Still on Zabbix, define a new trigger for the previously created item:<br />
<a href="http://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_trigger.png" rel="lightbox[1566]"><img src="http://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_trigger-300x160.png" alt="" title="Define a new trigger on Zabbix to monitor s3sync" width="300" height="160" class="aligncenter size-medium wp-image-1570" /></a><br />
Trigger expression: <code>{Template_AmazonCloud_Debian:vfs.file.regmatch[/var/log/s3sync.log,Synchronization failed].last(0)}=1</code>
</li>
</ol>
<p>With these few steps, you should now receive Zabbix alerts when a backup on S3 fails. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refresh GeoIP automatically</title>
		<link>http://www.logikdev.com/2011/11/07/refresh-geoip-automatically/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=refresh-geoip-automatically</link>
		<comments>http://www.logikdev.com/2011/11/07/refresh-geoip-automatically/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 22:55:09 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[GeoIP]]></category>
		<category><![CDATA[IP address]]></category>
		<category><![CDATA[MaxMind]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1440</guid>
		<description><![CDATA[GeoIP is a very useful tool provided by MaxMind. It can determine which country, region, city, postal code, and area code the visitor is coming from in real-time. For more information, visit MaxMind website. This tool is also coming with an Apache module allowing to redirect users depending on their location. For example, we could [...]]]></description>
			<content:encoded><![CDATA[<p><strong>GeoIP</strong> is a very useful tool provided by MaxMind. It can determine which country, region, city, postal code, and area code the visitor is coming from in real-time. For more information, visit <a href="http://www.maxmind.com/app/ip-locate" target="_blank">MaxMind website</a>.</p>
<p>This tool is also coming with an Apache module allowing to redirect users depending on their location. For example, we could redirect all users from France to the French home page of a multi-language website, or we could block the traffic to users from a specific country.</p>
<p>To install this module on a Debian server, you simply need to run the following command:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
apt-get install libapache2-mod-geoip
</pre>
<p><br/>But, how does this module work? How does it know where the user comes from?  <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' /><br />
It is actually quite simple: GeoIP is using a mapping file of IP address by country. On Debian, this file is stored in the folder <code>/usr/share/GeoIP</code> and is named <code>GeoIP.dat</code>.</p>
<p>However, the IP addresses are something which change all the time. So this file will get out-of-date very quickly. This is why MaxMind provides an updated file at the beginning of each month for free. To read the installation instructions, please click the following link: <a href="http://www.maxmind.com/app/installation" target="_blank">http://www.maxmind.com/app/installation</a></p>
<p>This is good and well, but who will remember or even have the time to update this file every month? And imagine if you have to do this on hundreds of servers?<br />
The solution is to use a shell script which will download, extract and install the updated GeoIP file automatically once a month:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh

# Go in the GeoIP folder
cd /usr/share/GeoIP

# Remove the previous GeoIP file (if present)
rm GeoIP.dat.gz

# Download the new GeoIP file
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

# Remove the previous GeoIP backup file
rm GeoIP.dat.bak

# Backup the existing GeoIP file
mv GeoIP.dat GeoIP.dat.bak

# Extract the new GeoIP file
gunzip GeoIP.dat.gz

# Change the permission of the GeoIP file
chmod 644 GeoIP.dat

# Reload Apache
service apache2 reload
</pre>
<p>You can place this file in your root folder and set up the following crontab job:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
0 0 3 * * /root/update_geoip.sh
</pre>
<p>This will execute the script automatically on the third day of every month.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/11/07/refresh-geoip-automatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>run-parts gives an exec format error</title>
		<link>http://www.logikdev.com/2011/05/23/run-parts-gives-an-exec-format-error/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=run-parts-gives-an-exec-format-error</link>
		<comments>http://www.logikdev.com/2011/05/23/run-parts-gives-an-exec-format-error/#comments</comments>
		<pubDate>Mon, 23 May 2011 22:51:33 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Exec format error]]></category>
		<category><![CDATA[run-parts]]></category>
		<category><![CDATA[shebang]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1255</guid>
		<description><![CDATA[I got a problem the other day with a Linux script I made. Basically, the script was working perfectly fine if I executed it directly from the command line but whenever I tried to run it with run-parts it failed! This is the error message it returned: Actually, the answer of this problem is quite [...]]]></description>
			<content:encoded><![CDATA[<p>I got a problem the other day with a Linux script I made.<br />
Basically, the script was working perfectly fine if I executed it directly from the command line but whenever I tried to run it with <code>run-parts</code> it failed!</p>
<p>This is the error message it returned:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
%prompt&gt; run-parts --report /etc/cron.daily
/etc/cron.daily/myscript:
run-parts: failed to exec /etc/cron.daily/myscript: Exec format error
run-parts: /etc/cron.daily/myscript exited with return code 1
%prompt&gt;
</pre>
<p>Actually, the answer of this problem is quite simple! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
I simply forgot the <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)">shebang</a> on the first line of the script&#8230;</p>
<p>So, if you get the same error than me, make sure you have the following line at the beginning of your script:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
#!/bin/sh
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/05/23/run-parts-gives-an-exec-format-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Segmentation fault at end of PHP script</title>
		<link>http://www.logikdev.com/2011/03/14/segmentation-fault-at-end-of-php-script/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=segmentation-fault-at-end-of-php-script</link>
		<comments>http://www.logikdev.com/2011/03/14/segmentation-fault-at-end-of-php-script/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 22:35:18 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[extensions]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Segmentation fault]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=1167</guid>
		<description><![CDATA[This one is a very strange problem! I created a little PHP script which connects to a MySQL database. Nothing amazing, except that I needed to run it via command line using the php command. What happened is that the script ran perfectly fine but, for some reason, it returned &#8220;Segmentation fault&#8221; when it reached [...]]]></description>
			<content:encoded><![CDATA[<p>This one is a very strange problem!<br />
I created a little PHP script which connects to a MySQL database. Nothing amazing, except that I needed to run it via command line using the <code>php</code> command. What happened is that the script ran perfectly fine but, for some reason, it returned &#8220;Segmentation fault&#8221; when it reached the end of the file! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' /><br />
It reminds me of the old days when I worked on C language, I used to see this not-very-useful message quite often. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Anyway, why do we get a &#8220;Segmentation fault&#8221; at the end of a PHP script? And when I say &#8216;the end&#8217;, I mean after any other lines!</p>
<p>Looking around the web, I found the following bug report: <a href="http://bugs.php.net/bug.php?id=43823">http://bugs.php.net/bug.php?id=43823</a><br />
This user seems to have the same problem than me except he is using a PostgreSQL database instead of a MySQL database.</p>
<p>Reading through the page, it looks like the problem comes from the order in which PHP loads his extensions! They explain that PostgreSQL should be loaded before cURL. If I apply the same logic, MySQL should then be loaded before cURL too.</p>
<p>To do that, we need to comment out the line <code>extension=curl.so</code> from the file <code>/etc/php5/cli/conf.d/curl.ini</code>:</p>
<pre class="brush: bash; title: ; notranslate">
# configuration for php CURL module
#extension=curl.so
</pre>
<p>And add it to the file <code>/etc/php5/cli/conf.d/mysql.ini</code> AFTER the line <code>extension=mysql.so</code>:</p>
<pre class="brush: bash; title: ; notranslate">
# configuration for php MySQL module
extension=mysql.so
extension=curl.so
</pre>
<p>To be honest, I don&#8217;t really like this solution as it is a bit messy. I would prefer PHP developers to fix the root cause or at least have a way to change the order in which PHP loads the extensions.</p>
<p><strong>NB:</strong> I was executing this PHP script on a Debian GNU/Linux 5.0 with Apache 2.2.9 and PHP 5.2.6.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/03/14/segmentation-fault-at-end-of-php-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ntpd process on D-Link DNS-313</title>
		<link>http://www.logikdev.com/2011/01/10/ntpd-process-on-dlink-dns313/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ntpd-process-on-dlink-dns313</link>
		<comments>http://www.logikdev.com/2011/01/10/ntpd-process-on-dlink-dns313/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 19:50:51 +0000</pubDate>
		<dc:creator>smoreau</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[D-Link]]></category>
		<category><![CDATA[DNS-313]]></category>
		<category><![CDATA[DNS-323]]></category>
		<category><![CDATA[fun_plug]]></category>
		<category><![CDATA[NAS]]></category>
		<category><![CDATA[NTP]]></category>
		<category><![CDATA[ntpd]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.logikdev.com/?p=992</guid>
		<description><![CDATA[During the configuration of a D-Link DNS-313 which is basically a NAS (Network-Attached Storage), I got a serious but easy-to-fix problem. In order to get access to the box by command line, I installed the Fonz fun_plug. I then wanted to automatically synchronise the internal time with some NTP Pool Time Servers. But, for some [...]]]></description>
			<content:encoded><![CDATA[<p>During the configuration of a <strong><a href="http://dlink.co.uk/cs/Satellite?c=Product_C&amp;childpagename=DLinkEurope-GB%2FDLProductCarouselMultiple&amp;cid=1197319418492&amp;p=1197318962342&amp;packedargs=ParentPageID%3D1197318962321%26TopLevelPageProduct%3DConsumer%26locale%3D1195806691854%26packedargs%3DProductParentID%253D1195808623796&amp;pagename=DLinkEurope-GB%2FDLWrapper">D-Link DNS-313</a></strong> which is basically a NAS (<a href="http://en.wikipedia.org/wiki/Network-attached_storage">Network-Attached Storage</a>), I got a serious but easy-to-fix problem. <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>In order to get access to the box by command line, I installed the <a href="http://www.inreto.de/dns323/fun-plug/0.5/">Fonz fun_plug</a>. I then wanted to automatically synchronise the internal time with some <a href="http://support.ntp.org/bin/view/Servers/NTPPoolServers">NTP Pool Time Servers</a>. But, for some reason, the version of the <code>ntpd</code> process provided with fun_plug is completely freezing the NAS. I wasn&#8217;t able to find the root cause of it, trust me, I tried everything I could think of!<br />
Please also note that the same process is working perfectly fine on his brother, the <strong><a href="http://dlink.co.uk/cs/Satellite?c=Product_C&amp;childpagename=DLinkEurope-GB%2FDLProductCarouselMultiple&amp;cid=1197319419183&amp;p=1197318962342&amp;packedargs=ParentPageID%3D1197318962321%26TopLevelPageProduct%3DConsumer%26locale%3D1195806691854%26packedargs%3DProductParentID%253D1195808623796&amp;pagename=DLinkEurope-GB%2FDLWrapper">D-Link DNS-323</a></strong>. As I said, I can&#8217;t explain why&#8230; <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' /> </p>
<p>But there is a good news! The <code>ntpd</code> process is actually part of the D-Link DNS-313 firmware. And it is working fine! <img src='http://www.logikdev.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  After double-checking, this process is however NOT part of the D-Link DNS-323 firmware. Why is that? Maybe D-Link got complaints from DNS-313 users and fixed it? Who knows&#8230;</p>
<p>Anyway, in order to get the <code>ntpd</code> process to work on the D-Link DNS-313, you need to replace the content of your <code>ntpd</code> startup script (<code>/ffp/start/ntpd.sh</code>) by the one below:</p>
<pre class="brush: bash; title: ; notranslate">
#!/ffp/bin/sh

# PROVIDE: ntpd
# REQUIRE: SERVERS
# BEFORE: LOGIN

. /ffp/etc/ffp.subr

name=&quot;ntpd&quot;
command=&quot;/usr/sbin/ntpd&quot;
ntpd_flags=&quot;-f /ffp/etc/ntpd.conf&quot;
required_files=&quot;/ffp/etc/ntpd.conf&quot;
start_cmd=&quot;ntpd_start&quot;

ntpd_start()
{
    # remove rtc and daylight cron jobs
    crontab -l | grep -vw '/usr/sbin/daylight' | grep -vw '/usr/sbin/rtc' | crontab -

    proc_start $command
}

run_rc_command &quot;$1&quot;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.logikdev.com/2011/01/10/ntpd-process-on-dlink-dns313/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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; title: ; notranslate">
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; title: ; notranslate">
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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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; title: ; notranslate">
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; title: ; notranslate">
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; title: ; notranslate">
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; title: ; notranslate">
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; title: ; notranslate">
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>6</slash:comments>
		</item>
	</channel>
</rss>

