<?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>shell | LogikDevelopment</title>
	<atom:link href="https://www.logikdev.com/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>https://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, 25 Apr 2017 13:57:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>
	<item>
		<title>Remove DOS carriage return</title>
		<link>https://www.logikdev.com/2012/09/26/remove-dos-carriage-return/</link>
					<comments>https://www.logikdev.com/2012/09/26/remove-dos-carriage-return/#comments</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Wed, 26 Sep 2012 22:36:53 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[carriage return]]></category>
		<category><![CDATA[DOS]]></category>
		<category><![CDATA[fileformat]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[vi]]></category>
		<category><![CDATA[Windows]]></category>
		<guid isPermaLink="false">https://www.logikdev.com/?p=1884</guid>

					<description><![CDATA[<p>After writing a shell script on Windows and trying to execute it on Linux, I got the following error message: The problem is obviously because the return line character on Windows and Linux are different. But how to fix it in order to execute it on Linux? I firstly tried to open it, copy the [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2012/09/26/remove-dos-carriage-return/">Remove DOS carriage return</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>After writing a shell script on Windows and trying to execute it on Linux, I got the following error message:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
/bin/sh^M: bad interpreter: No such file or directory
</pre>
<p>The problem is obviously because the return line character on Windows and Linux are different. But how to fix it in order to execute it on Linux?<br />
I firstly tried to open it, copy the content of the file and paste it in a new file using only Linux command line, but it didn&#8217;t work. <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f641.png" alt="🙁" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>However, I found the following thread which fixed the problem:<br />
<a href="http://www.reachdba.com/showthread.php?335-bin-sh-M-bad-interpreter-No-such-file-or-directory-apps11i-Instalation" target="_blank">http://www.reachdba.com/showthread.php?335-bin-sh-M-bad-interpreter-No-such-file-or-directory-apps11i-Instalation</a></p>
<p>Here is what you need to do:</p>
<ol>
<li>Open your file using <strong>vi</strong></li>
<li>Write the command <code>:set fileformat=unix</code></li>
<li>Save the file using <code>:wq</code></li>
</ol>
<p>The file should now run on Linux. <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p><p>The post <a href="https://www.logikdev.com/2012/09/26/remove-dos-carriage-return/">Remove DOS carriage return</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.logikdev.com/2012/09/26/remove-dos-carriage-return/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>CP2102 on DNS-323</title>
		<link>https://www.logikdev.com/2012/08/09/cp2102-on-dns-323/</link>
					<comments>https://www.logikdev.com/2012/08/09/cp2102-on-dns-323/#comments</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Thu, 09 Aug 2012 16:36:57 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[CP2101]]></category>
		<category><![CDATA[CP2102]]></category>
		<category><![CDATA[D-Link]]></category>
		<category><![CDATA[dmesg]]></category>
		<category><![CDATA[DNS-313]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Silicon Labs]]></category>
		<category><![CDATA[USB to RS232 converter]]></category>
		<guid isPermaLink="false">https://www.logikdev.com/?p=1834</guid>

					<description><![CDATA[<p>In one of my personal projects, I needed to connect and use a USB to RS232 (Serial) converter on my D-Link DNS-323. Weird requirements, I know. Anyway&#8230; 😐 Plenty of these converters exist out there, but I choose to go for a CP2102: Innocently, I first tried to compile the code source of this module [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2012/08/09/cp2102-on-dns-323/">CP2102 on DNS-323</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>In one of my personal projects, I needed to connect and use a USB to RS232 (Serial) converter on my D-Link DNS-323. Weird requirements, I know. Anyway&#8230; 😐<br />
Plenty of these converters exist out there, but I choose to go for a <a href="http://www.silabs.com/Support%20Documents/TechnicalDocs/cp2102.pdf" target="_blank"><strong>CP2102</strong></a>:</p>
<p><img decoding="async" class="aligncenter size-medium wp-image-1844" title="CP2102" src="https://www.logikdev.com/wp-content/uploads/2012/08/CP2102-300x125.jpg" alt="" width="300" height="125" srcset="https://www.logikdev.com/wp-content/uploads/2012/08/CP2102-300x125.jpg 300w, https://www.logikdev.com/wp-content/uploads/2012/08/CP2102.jpg 458w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>Innocently, I first tried to compile the code source of this module which can be found on the following page:<br />
<a href="http://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx" target="_blank">http://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx</a></p>
<p>After a few painful and unsuccessful tries, I decided to look around for the already-compiled module. 😉<br />
While wondering why I didn&#8217;t think of that before, I used the instructions below to install the required modules on my NAS:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
cd /mnt/HD_a2/ffp/lib/
mkdir modules
mkdir modules/2.6.12.6-arm1
cd modules/2.6.12.6-arm1
wget http://dev.skcserver.de/dns323/modules_v1.03/kernel/drivers/usb/serial/usbserial.ko
wget http://dev.skcserver.de/dns323/modules_v1.03/kernel/drivers/usb/serial/cp2101.ko
chmod 755 usbserial.ko
chmod 755 cp2101.ko
</pre>
<p>Once the modules are installed, the next step is to initialize them.<br />
I wrote the following script for this purpose so you can execute it anytime you need it:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh

insmod /ffp/lib/modules/2.6.12.6-arm1/usbserial.ko
insmod /ffp/lib/modules/2.6.12.6-arm1/cp2101.ko
mknod /dev/ttyUSB0 c 188 0
chmod 0666 /dev/ttyUSB0
</pre>
<p>At this point in time, you should have your module initialized on your D-Link DNS-323.<br />
You can check the kernel ring buffer using the <strong>dmesg</strong> command to verify it loaded properly.<br />
This is a snapshot of what I have in my kernel ring buffer after I ran the script above:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
usbcore: registered new driver usbserial
drivers/usb/serial/usb-serial.c: USB Serial support registered for Generic
usbcore: registered new driver usbserial_generic
drivers/usb/serial/usb-serial.c: USB Serial Driver core v2.0
drivers/usb/serial/usb-serial.c: USB Serial support registered for CP2101
CP2101 1-1:1.0: CP2101 converter detected
usb 1-1: reset full speed USB device using ehci_platform and address 5
usb 1-1: CP2101 converter now attached to ttyUSB0
usbcore: registered new driver CP2101
drivers/usb/serial/cp2101.c: Silicon Labs CP2101/CP2102 RS232 serial adaptor driver v0.04
</pre>
<p>Finally, you can test the communication with your USB to RS232 converter by connecting a LED between the RXD and 3V outputs and running the following script:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh

while &#x5B; true ]
do
echo &quot;hello world!!!&quot; &gt; /dev/ttyUSB0
echo &quot;sent&quot;
sleep 1
done
</pre>
<p>If you see the LED blinking, it means you succeed! 😀</p><p>The post <a href="https://www.logikdev.com/2012/08/09/cp2102-on-dns-323/">CP2102 on DNS-323</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.logikdev.com/2012/08/09/cp2102-on-dns-323/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Redirect traffic to a specific network</title>
		<link>https://www.logikdev.com/2012/05/06/redirect-traffic-to-a-specific-network/</link>
					<comments>https://www.logikdev.com/2012/05/06/redirect-traffic-to-a-specific-network/#comments</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Sun, 06 May 2012 12:29:22 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[route]]></category>
		<category><![CDATA[shell]]></category>
		<guid isPermaLink="false">https://www.logikdev.com/?p=1707</guid>

					<description><![CDATA[<p>This is a little trick which can be useful in some very specific case. For example, you could have a machine with two network cards. One of the network is behind a proxy and the other one is connected directly to the internet. You might want to forward all the traffic for google.com to the [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2012/05/06/redirect-traffic-to-a-specific-network/">Redirect traffic to a specific network</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>This is a little trick which can be useful in some very specific case.</p>
<p>For example, you could have a machine with two network cards. One of the network is behind a proxy and the other one is connected directly to the internet.<br />
You might want to forward all the traffic for google.com to the network which doesn&#8217;t have a proxy.</p>
<p>To do this, I am using the command <a href="http://linux.die.net/man/8/route" target="_blank"><strong>route</strong></a>:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
route add &lt;hostname&gt; &lt;target network&gt;
</pre>
<p>For example:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
route add google.com 192.168.101.1
</pre>
<p>Note that this command is available on both Linux and Mac.</p><p>The post <a href="https://www.logikdev.com/2012/05/06/redirect-traffic-to-a-specific-network/">Redirect traffic to a specific network</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.logikdev.com/2012/05/06/redirect-traffic-to-a-specific-network/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Install s3fs on Amazon Clouds</title>
		<link>https://www.logikdev.com/2012/04/03/install-s3fs-on-amazon-clouds/</link>
					<comments>https://www.logikdev.com/2012/04/03/install-s3fs-on-amazon-clouds/#respond</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Tue, 03 Apr 2012 21:38:02 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[FUSE filesystem]]></category>
		<category><![CDATA[hard links]]></category>
		<category><![CDATA[libfuse]]></category>
		<category><![CDATA[libxml]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[s3fs]]></category>
		<category><![CDATA[shell]]></category>
		<guid isPermaLink="false">https://www.logikdev.com/?p=1710</guid>

					<description><![CDATA[<p>s3fs is a FUSE filesystem that allows you to mount an Amazon S3 bucket as a local filesystem. It stores files natively and transparently in S3 (i.e., you can use other programs to access the same files). The following instructions detail the steps to install the program s3fs on an Amazon&#160;EC2 running Debian&#160;5.0.5. Install libfuse [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2012/04/03/install-s3fs-on-amazon-clouds/">Install s3fs on Amazon Clouds</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></description>
										<content:encoded><![CDATA[<blockquote><p>
s3fs is a FUSE filesystem that allows you to mount an Amazon S3 bucket as a local filesystem. It stores files natively and transparently in S3 (i.e., you can use other programs to access the same files).
</p></blockquote>
<p>The following instructions detail the steps to install the program <a href="http://code.google.com/p/s3fs/" target="_blank"><strong>s3fs</strong></a> on an Amazon&nbsp;EC2 running Debian&nbsp;5.0.5.</p>
<ol>
<li><strong>Install libfuse</strong><br />
First, you need to install the package libfuse manually as the one provided via apt-get is too old (s3fs needs a version greater than or equal to 2.8.4).</p>
<pre class="brush: bash; light: true; title: ; notranslate">
wget http://downloads.sourceforge.net/project/fuse/fuse-2.X/2.8.7/fuse-2.8.7.tar.gz
tar xzf fuse-2.8.7.tar.gz
cd fuse-2.8.7
./configure --prefix=/usr
make install
</pre>
</li>
<li><strong>Install libxml</strong><br />
You can simply install the package provided by apt-get:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
apt-get install libxml2-dev
</pre>
</li>
<li><strong>Upgrade mount</strong><br />
Because of a problem between fuse and mount, you need to upgrade the version of mount:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
wget http://www.kernel.org/pub/linux/utils/util-linux/v2.21/util-linux-2.21-rc1.tar.gz
tar xzf util-linux-2.21-rc1.tar.gz
./configure --prefix=/usr --without-ncurses
make install
</pre>
<p>For more information about this issue, please go to the following page: <a href="http://code.google.com/p/s3fs/issues/detail?id=228" target="_blank" title="Issue 228:	/bin/mount: unrecognized option '--no-canonicalize'">http://code.google.com/p/s3fs/issues/detail?id=228</a>
</li>
<li><strong>Install s3fs</strong><br />
You can now install s3fs using the following commands:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
wget http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz
tar xvzf s3fs-1.61.tar.gz
cd s3fs-1.61/
./configure --prefix=/usr
make install
</pre>
</li>
</ol>
<p>Note that I wanted to use s3fs to create incremental snapshot-style backups with rsync. Unfortunately, as mentioned on the following page, it didn&#8217;t work because s3fs doesn&#8217;t support <a href="http://en.wikipedia.org/wiki/Hard_link" target="_blank">hard links</a>: <a href="http://code.google.com/p/s3fs/issues/detail?id=46" target="_blank" title="Issue 46:	Does s3fs support hard links?">http://code.google.com/p/s3fs/issues/detail?id=46</a></p><p>The post <a href="https://www.logikdev.com/2012/04/03/install-s3fs-on-amazon-clouds/">Install s3fs on Amazon Clouds</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.logikdev.com/2012/04/03/install-s3fs-on-amazon-clouds/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>S3 command failed if the time is not synced</title>
		<link>https://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/</link>
					<comments>https://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/#comments</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Tue, 06 Dec 2011 23:11:43 +0000</pubDate>
				<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">https://www.logikdev.com/?p=1610</guid>

					<description><![CDATA[<p>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 [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/">S3 command failed if the time is not synced</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></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="https://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="https://s.w.org/images/core/emoji/17.0.2/72x72/1f62e.png" alt="😮" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 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="https://s.w.org/images/core/emoji/17.0.2/72x72/1f62f.png" alt="😯" class="wp-smiley" style="height: 1em; max-height: 1em;" /></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><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><p>The post <a href="https://www.logikdev.com/2011/12/06/s3-command-failed-if-time-not-synced/">S3 command failed if the time is not synced</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://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>https://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/</link>
					<comments>https://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/#respond</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 22:28:53 +0000</pubDate>
				<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">https://www.logikdev.com/?p=1566</guid>

					<description><![CDATA[<p>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 [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/">Monitor s3sync with Zabbix</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></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=$?
&#x5B; $RETVAL -eq 0 ] &amp;&amp; echo &quot;Synchronization succeed&quot;
&#x5B; $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="https://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_item.png"><img fetchpriority="high" decoding="async" src="https://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" srcset="https://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_item-297x300.png 297w, https://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_item.png 641w" sizes="(max-width: 297px) 100vw, 297px" /></a><br />
Item key: <code>vfs.file.regmatch[/var/log/s3sync.log,Synchronization failed]</code><br />

</li>
<li>Still on Zabbix, define a new trigger for the previously created item:<br />
<a href="https://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_trigger.png"><img decoding="async" src="https://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" srcset="https://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_trigger-300x160.png 300w, https://www.logikdev.com/wp-content/uploads/2011/11/zabbix_s3sync_trigger.png 665w" sizes="(max-width: 300px) 100vw, 300px" /></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. 🙂</p><p>The post <a href="https://www.logikdev.com/2011/11/24/monitor-s3sync-with-zabbix/">Monitor s3sync with Zabbix</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://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>https://www.logikdev.com/2011/11/07/refresh-geoip-automatically/</link>
					<comments>https://www.logikdev.com/2011/11/07/refresh-geoip-automatically/#comments</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Mon, 07 Nov 2011 22:55:09 +0000</pubDate>
				<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">https://www.logikdev.com/?p=1440</guid>

					<description><![CDATA[<p>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 [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2011/11/07/refresh-geoip-automatically/">Refresh GeoIP automatically</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></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>But, how does this module work? How does it know where the user comes from?  <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f62f.png" alt="😯" class="wp-smiley" style="height: 1em; max-height: 1em;" /><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><p>The post <a href="https://www.logikdev.com/2011/11/07/refresh-geoip-automatically/">Refresh GeoIP automatically</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.logikdev.com/2011/11/07/refresh-geoip-automatically/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>run-parts gives an exec format error</title>
		<link>https://www.logikdev.com/2011/05/23/run-parts-gives-an-exec-format-error/</link>
					<comments>https://www.logikdev.com/2011/05/23/run-parts-gives-an-exec-format-error/#comments</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Mon, 23 May 2011 22:51:33 +0000</pubDate>
				<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">https://www.logikdev.com/?p=1255</guid>

					<description><![CDATA[<p>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: %prompt&#62; run-parts --report /etc/cron.daily /etc/cron.daily/myscript: run-parts: failed to [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2011/05/23/run-parts-gives-an-exec-format-error/">run-parts gives an exec format error</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></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="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /><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><p>The post <a href="https://www.logikdev.com/2011/05/23/run-parts-gives-an-exec-format-error/">run-parts gives an exec format error</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.logikdev.com/2011/05/23/run-parts-gives-an-exec-format-error/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Segmentation fault at end of PHP script</title>
		<link>https://www.logikdev.com/2011/03/14/segmentation-fault-at-end-of-php-script/</link>
					<comments>https://www.logikdev.com/2011/03/14/segmentation-fault-at-end-of-php-script/#comments</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Mon, 14 Mar 2011 22:35:18 +0000</pubDate>
				<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">https://www.logikdev.com/?p=1167</guid>

					<description><![CDATA[<p>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 [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2011/03/14/segmentation-fault-at-end-of-php-script/">Segmentation fault at end of PHP script</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></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="https://s.w.org/images/core/emoji/17.0.2/72x72/1f62f.png" alt="😯" class="wp-smiley" style="height: 1em; max-height: 1em;" /><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="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></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><p>The post <a href="https://www.logikdev.com/2011/03/14/segmentation-fault-at-end-of-php-script/">Segmentation fault at end of PHP script</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.logikdev.com/2011/03/14/segmentation-fault-at-end-of-php-script/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>ntpd process on D-Link DNS-313</title>
		<link>https://www.logikdev.com/2011/01/10/ntpd-process-on-dlink-dns313/</link>
					<comments>https://www.logikdev.com/2011/01/10/ntpd-process-on-dlink-dns313/#comments</comments>
		
		<dc:creator><![CDATA[smoreau]]></dc:creator>
		<pubDate>Mon, 10 Jan 2011 19:50:51 +0000</pubDate>
				<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">https://www.logikdev.com/?p=992</guid>

					<description><![CDATA[<p>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 [&#8230;]</p>
<p>The post <a href="https://www.logikdev.com/2011/01/10/ntpd-process-on-dlink-dns313/">ntpd process on D-Link DNS-313</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></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="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></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="https://s.w.org/images/core/emoji/17.0.2/72x72/1f644.png" alt="🙄" class="wp-smiley" style="height: 1em; max-height: 1em;" /></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="https://s.w.org/images/core/emoji/17.0.2/72x72/1f600.png" alt="😀" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 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><p>The post <a href="https://www.logikdev.com/2011/01/10/ntpd-process-on-dlink-dns313/">ntpd process on D-Link DNS-313</a> first appeared on <a href="https://www.logikdev.com">LogikDevelopment</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.logikdev.com/2011/01/10/ntpd-process-on-dlink-dns313/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
