<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>G-Loaded Journal &#187; Scripts</title>
	<atom:link href="http://www.g-loaded.eu/tag/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g-loaded.eu</link>
	<description>An open-source software and technology related journal</description>
	<lastBuildDate>Thu, 02 Sep 2010 17:01:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>Script for Apache Error Report</title>
		<link>http://www.g-loaded.eu/2010/03/28/script-apache-error-report/</link>
		<comments>http://www.g-loaded.eu/2010/03/28/script-apache-error-report/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 17:26:47 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cron]]></category>
		<category><![CDATA[Report]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Servers]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1648</guid>
		<description><![CDATA[The last incident with the php-cgi errors as a result of a bad PHP script made me re-evaluate the daily reports I receive from the server. I realized that a report about the httpd errors that have occured during the previous day, including all virtualhosts, is more important than I had initially thought. Such a [...]]]></description>
			<content:encoded><![CDATA[<p>The last incident with the <a href="http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/">php-cgi errors</a> as a result of a bad PHP script made me re-evaluate the daily reports I receive from the server. I realized that a report about the <em>httpd errors</em> that have occured during the previous day, including all virtualhosts, is more important than I had initially thought. Such a report would have brought the problem to my attention much earlier and could also point me to the right direction while I was trying to figure out what was the cause of it. Fortunately, I found a nice error report generator for this purpose.<br />
<span id="more-1648"></span><br />
The script is called <a href="http://www.librelogiciel.com/software/ScanErrLog/action_Presentation">scanerrlog</a> and has some quite nice features. I highly recommend you check it out. In order to run it you will also need an extra Python module, <a href="http://www.librelogiciel.com/software/jaxml/action_Presentation">jaxml</a>. Download both packages and extract <strong>scanerrlog.py</strong> and <strong>jaxml.py</strong> to the same directory. Then you can call <code>scanerrlog.py</code> using the following cronjob.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/env bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Error Report for httpd</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Requires:</span>
<span style="color: #666666; font-style: italic;">#   - scanerrlog - http://www.librelogiciel.com/software/ScanErrLog/action_Presentation</span>
<span style="color: #666666; font-style: italic;">#   - jaxml - http://www.librelogiciel.com/software/jaxml/action_Presentation</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>error_log \
    <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>vhosts<span style="color: #000000; font-weight: bold;">/*/</span>log<span style="color: #000000; font-weight: bold;">/</span>error_log \
    <span style="color: #000000; font-weight: bold;">|</span> python <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>scanerrlog.py <span style="color: #660033;">-f</span> text \
    <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`hostname`</span> - Apache Error Report&quot;</span> root<span style="color: #000000; font-weight: bold;">@</span>localhost
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Some notes:</p>
<ol>
<li>Make sure that this cronjob runs before <strong>log rotation</strong> takes place.</li>
<li>The above shell script concatenates the <strong>error_log</strong> files from the main web server and all <em>virtualhosts</em>. Edit the paths to reflect your server configuration and virtualhost layout.</li>
<li>Edit the path to <code>scanerrlog.py</code>.</li>
</ol>
<p>Scanerrlog has some quite nice features that let you further customize the report. Make sure you read the help message.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/">Script for Apache Error Report</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/" rel="bookmark">SELinux audit reports script</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/05/strange-mod_dav_svn-error/" rel="bookmark">Strange mod_dav_svn error</a></li>
<li><a href="http://www.g-loaded.eu/2007/08/10/ssl-enabled-name-based-apache-virtual-hosts-with-mod_gnutls/" rel="bookmark">SSL-enabled Name-based Apache Virtual Hosts with mod_gnutls</a></li>
<li><a href="http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/" rel="bookmark">How to integrate seaudit-report in logwatch</a></li>
<li><a href="http://www.g-loaded.eu/2007/07/29/when-it-comes-to-error-messages/" rel="bookmark">When it comes to error messages&#8230;</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/03/28/script-apache-error-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Using a switch to prevent system shutdown/reboot/suspend</title>
		<link>http://www.g-loaded.eu/2008/11/26/using-a-switch-to-prevent-system-shutdownrebootsuspend/</link>
		<comments>http://www.g-loaded.eu/2008/11/26/using-a-switch-to-prevent-system-shutdownrebootsuspend/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 21:36:30 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[GNOME]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[System]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=658</guid>
		<description><![CDATA[What I tried to accomplish today was to prevent a system shutdown or reboot or suspend, if a specific process was still running in the background. This might sound pretty useless, but having shut my PC down once again this afternoon while the backup process was still active in the background, I decided to resolve [...]]]></description>
			<content:encoded><![CDATA[<p>What I tried to accomplish today was to <em>prevent</em> a system <strong>shutdown</strong> or <strong>reboot</strong> or <strong>suspend</strong>, if a specific process was still running in the background. This might sound pretty useless, but having shut my PC down once again this afternoon while the backup process was still active in the background, I decided to resolve this issue for good. But things are not that easy as they might seem&#8230; After many hours of digging into the operating system&#8217;s <strong>initscripts</strong>, <strong>upstart events</strong> and the methods used by GNOME to perform a shutdown/reboot/suspend, I am still away from a decent solution that will, not only work when directly invoking the relevant commands from the <strong>console</strong>, but also when I perform the aforementioned actions from the <strong>GNOME shutdown applet</strong>. Here is what I&#8217;ve tried so far&#8230;<br />
<span id="more-658"></span><br />
First of all, having failed with all the initscript or upstart event modifications I&#8217;ve tried, I decided to completely override the relevant commands, for instance <code>/sbin/shutdown</code>, by placing a wrapper script with the same name in <code>/usr/local/sbin/</code>. Here is such a wrapper script for the shutdown command, saved as <code>/usr/local/sbin/shutdown</code>:</p>
<pre class="codesnp">
#! /bin/sh

if [ -f /var/lock/noshutdown.lock ] ; then
  logger -t shutdowndog shutdown prevented
  exit 1
fi

/sbin/shutdown "$@"
</pre>
<p>Then, I created the file that would act as a <strong>switch</strong>:</p>
<pre class="console">
touch /var/lock/noshutdown.lock
</pre>
<p>Then, I initiated the <strong>shutdown procedure</strong> from the command line:</p>
<pre class="console">
shutdown -h +0
</pre>
<p>There was no shutdown! It had worked!</p>
<p>Syslog confirmed that the check had taken place:</p>
<pre class="codesnp">
Nov 25 19:19:04 galeon shutdowndog: shutdown prevented
</pre>
<p>I rushed to try to shut down the system from GNOME&#8217;s shutdonw panel (<code>Menu System -> Shut Down...</code>), but, after pressing the relevant button, the system went down normally&#8230;</p>
<p>It was obvious that GNOME had not used my override, but another mechanism to power-off the system instead. Since I use the GNOME menu to shutdown/reboot/suspend the system, I spent a couple of hours trying to find what was going on in GNOME and finally discovered the file <code>/usr/bin/gnome-power-cmd.sh</code>:</p>
<pre class="codesnp">
#!/bin/sh
# Copyright (C) 2007 Richard Hughes <richard@hughsie.com>
#
# Licensed under the GNU General Public License Version 2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

#$1 = method name
execute_dbus_method ()
{
        dbus-send --session --dest=org.freedesktop.PowerManagement              \
                  --type=method_call --print-reply --reply-timeout=2000 \
                  /org/freedesktop/PowerManagement                      \
                  org.freedesktop.PowerManagement.$1
        if [ $? -eq 0 ]; then
                echo "Failed"
        fi
}

if [ "$1" = "suspend" ]; then
        echo "Suspending"
        execute_dbus_method "Suspend"
elif [ "$1" = "hibernate" ]; then
        echo "Hibernating"
        execute_dbus_method "Hibernate"
elif [ "$1" = "reboot" ]; then
        echo "Rebooting"
        execute_dbus_method "Reboot"
elif [ "$1" = "shutdown" ]; then
        echo "Shutting down"
        execute_dbus_method "Shutdown"
elif [ "$1" = "" ]; then
        echo "command required: suspend, shutdown, hibernate or reboot"
else
        echo "command '$1' not recognised, only suspend, shutdown, hibernate or reboot are valid"
        exit 1
fi
</pre>
<p>So, GNOME makes the appropriate calls for power-related events through <strong>D-bus</strong>. I initially thought that GNOME used <code>/usr/bin/gnome-power-cmd.sh</code> whenever the shutdown/reboot/suspend button was pressed, so I modified it so to check for my switch (<code>/var/lock/noshutdown.lock</code>) and then proceed accordingly. It did not work out&#8230;</p>
<p>I had already spent much time on this, so I decided to quit. But, it is crucial for me to make this thing work and I will probably investigate it a bit more and report back at some later time.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2008/11/26/using-a-switch-to-prevent-system-shutdownrebootsuspend/">Using a switch to prevent system shutdown/reboot/suspend</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2008/11/28/delayed-shutdown-initscript/" rel="bookmark">delayed-shutdown initscript</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/30/selinux-setenforce-mode/" rel="bookmark">Using setenforce to switch SELinux mode wisely</a></li>
<li><a href="http://www.g-loaded.eu/2008/06/18/use-the-alternatives-system-to-switch-to-a-custom-firefox-release/" rel="bookmark">Use the Alternatives System to switch to a custom Firefox release</a></li>
<li><a href="http://www.g-loaded.eu/2007/03/15/screenshot-of-a-menu-under-gnome-round-2/" rel="bookmark">Screenshot of a menu under GNOME: ROUND 2</a></li>
<li><a href="http://www.g-loaded.eu/2007/03/05/print-a-man-page/" rel="bookmark">Print a Man Page</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2008/11/26/using-a-switch-to-prevent-system-shutdownrebootsuspend/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Send to Desktop &#8211; Create Symlink</title>
		<link>http://www.g-loaded.eu/2008/11/04/send-to-desktop-create-symlink/</link>
		<comments>http://www.g-loaded.eu/2008/11/04/send-to-desktop-create-symlink/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 22:07:12 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/?p=646</guid>
		<description><![CDATA[Having set up automatic incremental backups for my home directory, I need to follow some simple rules in order not to poison the backups with temporary files (sometimes huge ones) I usually place on my desktop for later viewing. One of those rules is to stop downloading stuff directly to the desktop, but use a [...]]]></description>
			<content:encoded><![CDATA[<p>Having set up <strong>automatic incremental backups</strong> for my <em>home directory</em>, I need to follow some simple rules in order not to poison the backups with temporary files (sometimes huge ones) I usually place on my desktop for later viewing. One of those <strong>rules</strong> is to stop downloading stuff directly to the desktop, but use a dedicated directory for that purpose, for instance <code>~/Download</code>, which is excluded from the automatic backups. Since the downloads directory is usually a mess, I needed a quick way to create one or more symbolic links on my desktop pointing to files inside <code>Downloads/</code>. The normal approach would have been to create a <em>Nautilus Action</em>, but it seems that this tool is not very efficient since it has issues with paths that contain spaces. If quotes are used in order to make &#8220;<em>paths with spaces</em>&#8221; work, it still cannot successfully create the symbolic link. So, I decided to write a small shell script that can create symbolic links on the desktop for the selected files or directories. It supports paths containing spaces and also multi-selection of items (files/dirs) and will warn you before creating multiple symlinks.<br />
<span id="more-646"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/env bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  Send to Desktop - Create Symlink</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  Project: http://www.g-loaded.eu/2008/11/03/send-to-desktop-create-symlink/</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  Features:</span>
<span style="color: #666666; font-style: italic;">#      - creates symlinks on the desktop pointing to each of the selected items</span>
<span style="color: #666666; font-style: italic;">#        (files/directories).</span>
<span style="color: #666666; font-style: italic;">#      - Supports paths containing spaces.</span>
<span style="color: #666666; font-style: italic;">#      - Supports multi-selection (warns before creating multiple symlinks)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  Requires:</span>
<span style="color: #666666; font-style: italic;">#      - ln</span>
<span style="color: #666666; font-style: italic;">#      - zenity</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  Installation:</span>
<span style="color: #666666; font-style: italic;">#  1) Put the file in ~/.gnome2/nautilus-scripts/</span>
<span style="color: #666666; font-style: italic;">#       cp &quot;Send to Desktop - Create Symlink&quot; ~/.gnome2/nautilus-scripts/</span>
<span style="color: #666666; font-style: italic;">#  2) Set the 'executable' bit:</span>
<span style="color: #666666; font-style: italic;">#       chmod -x ~/.gnome2/nautilus-scripts/&quot;Send to Desktop - Create Symlink&quot;</span>
<span style="color: #666666; font-style: italic;">#  3) Access the script by right clicking and selecting the submenu 'scripts'</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  Copyright 2008 George Notaras &amp;lt;gnot [at] g-loaded.eu&amp;gt;, CodeTRAX.org</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span style="color: #666666; font-style: italic;">#  you may not use this file except in compliance with the License.</span>
<span style="color: #666666; font-style: italic;">#  You may obtain a copy of the License at</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#      http://www.apache.org/licenses/LICENSE-2.0</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  Unless required by applicable law or agreed to in writing, software</span>
<span style="color: #666666; font-style: italic;">#  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span style="color: #666666; font-style: italic;">#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span style="color: #666666; font-style: italic;">#  See the License for the specific language governing permissions and</span>
<span style="color: #666666; font-style: italic;">#  limitations under the License.</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">DESKTOP</span>=~<span style="color: #000000; font-weight: bold;">/</span>Desktop
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
  zenity <span style="color: #660033;">--error</span> <span style="color: #660033;">--text</span> <span style="color: #ff0000;">&quot;At least one file or directory must be selected.&quot;</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
  zenity <span style="color: #660033;">--question</span> <span style="color: #660033;">--text</span> <span style="color: #ff0000;">&quot;Multiple items selected. Proceed?&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> item <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;$@&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PWD</span>/<span style="color: #007800;">$item</span>&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DESKTOP</span>/<span style="color: #007800;">$(basename $item)</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Save the code in a file. Assuming that you have saved it as &#8220;<strong>Send to Desktop &#8211; Create Symlink</strong>&#8220;, follow the instructions below in order to install and use it:</p>
<p><strong>1 &#8211;</strong> Put the file in ~/.gnome2/nautilus-scripts/</p>
<pre class="console">
cp "Send to Desktop - Create Symlink" ~/.gnome2/nautilus-scripts/
</pre>
<p><strong>2 &#8211;</strong> Set the &#8216;<em>executable</em>&#8216; bit:</p>
<pre class="console">
chmod +x ~/.gnome2/nautilus-scripts/"Send to Desktop - Create Symlink"
</pre>
<p><strong>3 &#8211;</strong> Access the script by right clicking and selecting the submenu &#8216;<em>scripts</em>&#8216;</p>
<p>Enjoy!</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2008/11/04/send-to-desktop-create-symlink/">Send to Desktop &#8211; Create Symlink</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2005/11/10/search-for-viruses-from-nautilus/" rel="bookmark">Search for viruses from Nautilus</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/add-files-to-totem-playing-list-from-nautilus/" rel="bookmark">Add files to Totem playing list from Nautilus</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/print-to-cups-printer-instances/" rel="bookmark">Print to CUPS printer instances</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/mass-download/" rel="bookmark">Mass download</a></li>
<li><a href="http://www.g-loaded.eu/2007/10/18/dictionary-lookups-anywhere/" rel="bookmark">Dictionary Lookups Anywhere</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2008/11/04/send-to-desktop-create-symlink/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Upgraded to WordPress 2.3.1</title>
		<link>http://www.g-loaded.eu/2007/11/04/upgraded-to-wordpress-231/</link>
		<comments>http://www.g-loaded.eu/2007/11/04/upgraded-to-wordpress-231/#comments</comments>
		<pubDate>Sat, 03 Nov 2007 22:13:33 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/2007/11/04/upgraded-to-wordpress-231/</guid>
		<description><![CDATA[I finally made the decision to upgrade WordPress to the latest 2.3.1 version. I skipped the initial v2.3 release as I had read that there was a lengthy list of bugs about that release, which eventually have been fixed in 2.3.1. Everything seems to run smoothly. I intend to spend some time browsing around my [...]]]></description>
			<content:encoded><![CDATA[<p>I finally made the decision to upgrade WordPress to the latest 2.3.1 version. I skipped the initial v2.3 release as I had read that there was a lengthy list of bugs about that release, which eventually have been fixed in 2.3.1. Everything seems to run smoothly. I intend to spend some time browsing around my website to test it and by the way fix a few things here and there.</p>
<p>A while ago I had written a script that would automate the WordPress upgrade process. Such a program could have been a simple shell script, just a few lines of code. However, I decided to write a more flexible script in Python instead, which can keep backups, perform a thorough upgrade of the website&#8217;s platform, keep the files I need to keep etc. A script that takes good care of everything while upgrading is also a good idea because it minimizes downtime while performing upgrades. Today was the first time to test it. After the upgrade, everything seems to be where it should. The script is in pre-alpha state and despite the fact that I used it on my website, it is not ready for release yet. Below is the output of the upgrade on G-Loaded:<br />
<span id="more-455"></span></p>
<pre class="codesnp">
# python wpupgrade.py 2.3.1
info: ++ Performings Tests. Please wait...
info: Initial configuration checks - OK
info: Retrieval of WordPress database settings from wp-config.php - OK
info: Checking existence of mysqldump - OK
info: ++ Starting data backup. Please wait...
info: Database backup - OK
info: Filesystem backup - OK
info: Data backup Complete
info: ++ Downloading wordpress archive. Please wait...
info: Download and Verification Complete
info: ++ Removing old WordPress files and directories. Listing follows:
info: Removed DIR: wp-admin
info: Removed DIR: wp-includes - PRESERVED wp-includes/languages
warning: --> DIR wp-content/cache CANNOT BE REMOVED - NOT CRITICAL - REMOVE MANUALLY IF POSSIBLE
info: Removed FILE: wp-commentsrss2.php
info: Removed FILE: wp-rss.php
info: Removed FILE: wp-rdf.php
info: Removed FILE: wp-login.php
info: Removed FILE: wp-app.php
info: Removed FILE: wp-settings.php
info: Removed FILE: wp-comments-post.php
info: Removed FILE: wp-mail.php
info: Removed FILE: wp-rss2.php
info: Removed FILE: wp-pass.php
info: Removed FILE: wp-blog-header.php
info: Removed FILE: wp-register.php
info: Removed FILE: wp-feed.php
info: Removed FILE: wp-trackback.php
info: Removed FILE: wp-cron.php
info: Removed FILE: wp-links-opml.php
info: Removed FILE: wp-config-sample.php
info: Removed FILE: wp-atom.php
info: Removed FILE: index.php
info: Removed FILE: xmlrpc.php
info: Removed FILE: readme.html
info: Removed FILE: license.txt
info: WordPress files removal complete
info: ++ WordPress Upgrade
info: Writing new files. Please wait...
info: File Upgrade Complete
info: ++ Starting Cleanup
info: Nothing - TODO
info: Finish Upgrade by visiting: http://www.yoursite.org/wp-admin/upgrade.php
</pre>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2007/11/04/upgraded-to-wordpress-231/">Upgraded to WordPress 2.3.1</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2008/12/17/upgraded-to-wordpress-coltrane/" rel="bookmark">Upgraded to WordPress Coltrane</a></li>
<li><a href="http://www.g-loaded.eu/2006/01/01/upgraded-to-wordpress-2/" rel="bookmark">Upgraded to WordPress 2</a></li>
<li><a href="http://www.g-loaded.eu/2007/03/03/highly-exploitable-code-planted-into-wordpress-211/" rel="bookmark">Highly Exploitable Code Planted into WordPress 2.1.1</a></li>
<li><a href="http://www.g-loaded.eu/2008/03/31/wordpress-25-plugin-compatibility/" rel="bookmark">WordPress 2.5 &#8211; Plugin Compatibility</a></li>
<li><a href="http://www.g-loaded.eu/2007/02/09/server-upgraded-to-fedora-6/" rel="bookmark">Server upgraded to Fedora 6</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2007/11/04/upgraded-to-wordpress-231/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Dictionary Lookups Anywhere</title>
		<link>http://www.g-loaded.eu/2007/10/18/dictionary-lookups-anywhere/</link>
		<comments>http://www.g-loaded.eu/2007/10/18/dictionary-lookups-anywhere/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 17:40:22 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Dictionaries]]></category>
		<category><![CDATA[GNOME]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Resolved]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/2007/10/18/dictionary-lookups-anywhere/</guid>
		<description><![CDATA[I consider ditionaries, either in printed or electronic form, as one of the most useful sources of valuable information and an indispensable companion when reading. Lately, I&#8217;ve been reading lots of stuff, which involved scientific terminology in the English language, so it was very often required to lookup words on various online dictionaries. I did [...]]]></description>
			<content:encoded><![CDATA[<p>I consider ditionaries, either in printed or electronic form, as one of the most useful sources of valuable information and an indispensable companion when reading. Lately, I&#8217;ve been reading lots of stuff, which involved scientific terminology in the English language, so it was very often required to lookup words on various online dictionaries. I did most of the reading using <a href="http://www.gnome.org/projects/epiphany/">epiphany</a> or <a href="http://www.gnome.org/projects/evince/">evince</a>. Epiphany has a very handy feature which can send the selected text to a <a href="http://www.g-loaded.eu/2007/05/11/smart-bookmarks-in-epiphany/">smart bookmark</a> or even to <a href="http://en.wikipedia.org/wiki/Gnome-dictionary">gnome-dictionary</a>. Unfortunately, evince lacks such features, so I had to manually copy and paste words to the web browser in order to look them up on the web. This, combined with evince&#8217;s performance issues (version 0.6.0 &#8211; Fedora Core 6), led me to look for a more universal method of looking up words or phrases, regardless of the document viewer. And, usually, when your sole ambition becomes to overcome an annoying situation, a solution is on the way.<br />
<span id="more-446"></span><br />
What I needed was the following:</p>
<ol>
<li>Select some text with the mouse (easy :P)</li>
<li>Trigger a dictionary lookup for the selected text.</li>
<li>Get the word&#8217;s definitions in a browser window.</li>
</ol>
<p>After some research on the web, I came up with a decent solution. I discovered that when some text is selected under X, it is temporarily stored in a location called &#8220;<em>Primary Clipboard</em>&#8220;. The text could be somehow retrieved from that location and could be sent to an online dictionary by pressing a specific keyboard combination. This is totally independent of the application which the text had been selected from. This method also makes <strong>dictionary lookups as easy and fast as it can get</strong>.</p>
<p>But, this was just in theory. I needed a way of retrieving the selected text from the primary clipboard programmatically. This was the most difficult part, as X or GTK programming is out of my league&#8230;</p>
<p>Fortunately, I was told that this exact functionality exists in the <a href="http://raphael.slinckx.net/deskbar/">deskbar applet</a>. The user can select some text, then press <strong>Alt-F3</strong> and the deskbar applet displays a list of pre-defined places (epiphany smart bookmarks included) to search for the selected text, which also includes gnome-dictionary in order to look up the word on a dictionary server.</p>
<p>Using this deskbar applet&#8217;s functionality for the dictionary lookups could be the perfect solution. But, on the other hand, being able to specify different key combinations for different dictionaries and not having to pick a search location from the deskbar&#8217;s list would be more than perfect. Grepping into deskbar applet&#8217;s source code I soon found what I was looking for in the first place: that is <em>the way to programmatically retrieve the selected text from the primary clipboard</em>. Of course, I shamelessly stole that small piece of code :P</p>
<p>Provided that some text has been selected, its retrieval is possible with the following python snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> gtk
clipboard = gtk.<span style="color: black;">clipboard_get</span><span style="color: black;">&#40;</span>selection = <span style="color: #483d8b;">&quot;PRIMARY&quot;</span><span style="color: black;">&#41;</span>
text = clipboard.<span style="color: black;">wait_for_text</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> text</pre></div></div>

<p>The rest was easy. What was needed was a key combination to trigger the execution of the above script. Unfortunately, a custom command cannot be set in the <strong>gnome-keybinding-properties</strong> application. So, a workaround was needed even for that!! After some research, it turned out that one can set a <strong>custom command</strong> and assign a keyboard shortcut for it in GNOME&#8217;s window manager, <a href="http://en.wikipedia.org/wiki/Metacity">metacity</a>.</p>
<p>So, finally, it worked! Read on for detailed info&#8230;</p>
<h4>How to set things up</h4>
<p>First of all, create a small script:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
&nbsp;
command = <span style="color: #483d8b;">&quot;epiphany -n http://en.wiktionary.org/wiki/%s&quot;</span>
<span style="color: #808080; font-style: italic;">#command = &quot;epiphany -n http://dictionary.reference.com/search?q=%s&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> gtk
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">urllib</span> <span style="color: #ff7700;font-weight:bold;">import</span> quote
&nbsp;
clipboard = gtk.<span style="color: black;">clipboard_get</span><span style="color: black;">&#40;</span>selection = <span style="color: #483d8b;">&quot;PRIMARY&quot;</span><span style="color: black;">&#41;</span>
text = clipboard.<span style="color: black;">wait_for_text</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
text = text.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> text:
	text = quote<span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span>	<span style="color: #808080; font-style: italic;"># This is basically for multiword selections</span>
	<span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>command <span style="color: #66cc66;">%</span> text<span style="color: black;">&#41;</span></pre></div></div>

<p>Save the script to a directory of your choice. The rest assumes that the script has been saved to:</p>
<p><strong>/home/johndoe/bin/selectionlookup.py</strong></p>
<p>What this does is to retrieve the selected text from the &#8220;<em>primary clipboard</em>&#8221; and execute the specified command. In this case, the command is actually a system call to the epiphany browser which is instructed to load a page with the possible definitions for the selected text. The English version of <a href="http://en.wiktionary.org/">Wiktionary</a> or <a href="http://dictionary.reference.com/">Dictionary.com</a> (whichever is uncommented) is used for the lookup. Note that <strong>multiword selections are supported</strong> by both the script above and the aforementioned online dictionaries.</p>
<p><a name="customkeybinding"></a><br />
Second of all, a <strong>global keyboard shortcut</strong> needs to be set in metacity for the reasons I explained previously.</p>
<p>First, the custom command needs to be set. Open the <strong>gconf-editor</strong> and browse to the key:</p>
<pre class="codesnp">
/apps/metacity/keybinding_commands/command_1
</pre>
<p>Of course use any command key you wish. Here <code>command_1</code> is used. Set the following value:</p>
<pre class="codesnp">
python /home/johndoe/bin/selectionlookup.py
</pre>
<p>Then set up the keybinding for that command. Browse to the key:</p>
<pre class="codesnp">
/apps/metacity/global_keybindings/run_command_1
</pre>
<p>And set the combination (the following is an example):</p>
<pre class="codesnp">
&lt;control&gt;&lt;alt&gt;g
</pre>
<p>Test it by selecting some text anywhere and by pressing <code>Ctrl-Alt-g</code>. A new tab will appear in the browser window with a page with the selected text&#8217;s definitions (if any).</p>
<h4>Appendix I: Using a dictionary server</h4>
<p>Instead of looking the selected text up on a web-based dictionary, you can retrieve definitions from a dictionary server. Adjust the script accordingly. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
&nbsp;
command = <span style="color: #483d8b;">&quot;echo 'DEFINE * <span style="color: #000099; font-weight: bold;">\&quot;</span>%s<span style="color: #000099; font-weight: bold;">\&quot;</span>' | nc dict.org 2628 | zenity --text-info --title='Dict Lookup' --width=500 --height=500&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> gtk
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
&nbsp;
clipboard = gtk.<span style="color: black;">clipboard_get</span><span style="color: black;">&#40;</span>selection = <span style="color: #483d8b;">&quot;PRIMARY&quot;</span><span style="color: black;">&#41;</span>
text = clipboard.<span style="color: black;">wait_for_text</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
text = text.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> text:
	<span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>command <span style="color: #66cc66;">%</span> text<span style="color: black;">&#41;</span></pre></div></div>

<p>The following happens when the keyboard shortcut is pressed:</p>
<ol>
<li>The following dictionary protocol specific command: <strong>DEFINE * &#8220;selectedtext&#8221;</strong> is piped to netcat (see some <a href="http://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples/">netcat examples</a>).</li>
<li>Netcat opens a connection to the <code>dict.org</code> dictionary server, sends the command and retrieves the results.</li>
<li>The results are piped to <a href="http://freshmeat.net/projects/zenity">zenity</a> and are displayed in an information textbox.</li>
</ol>
<p>Obviously, in order to successfully run the above command you will need <strong>netcat</strong> (<strong>nc</strong>) and <strong>zenity</strong>.</p>
<h4>Final Thoughts</h4>
<p>A whole dictionary application can be built around the selected text that is stored at the primary clipboard. The above is the fastest and most effective way of retrieving word/phrase definitions from any possible dictionary. It is independent of the application from which the text is selected and no time is wasted in meaningless copy-pasting. If you know a better way of looking up words, please let me know.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2007/10/18/dictionary-lookups-anywhere/">Dictionary Lookups Anywhere</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2006/05/17/epiphany-python-console-open-new-tab/" rel="bookmark">Epiphany Python Console &#8211; Open New Tab</a></li>
<li><a href="http://www.g-loaded.eu/2006/03/16/dictexpress/" rel="bookmark">DictExpress</a></li>
<li><a href="http://www.g-loaded.eu/2007/02/28/taking-a-screenshot-of-a-menu-under-gnome/" rel="bookmark">Taking a screenshot of a menu under GNOME</a></li>
<li><a href="http://www.g-loaded.eu/2007/10/19/zim-a-desktop-wiki/" rel="bookmark">Zim &#8211; a Desktop Wiki</a></li>
<li><a href="http://www.g-loaded.eu/2006/09/23/use-python-to-get-the-web-page-data-in-epiphany/" rel="bookmark">Use Python to get the web page data in Epiphany</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2007/10/18/dictionary-lookups-anywhere/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Use wget or curl to download from RapidShare Premium</title>
		<link>http://www.g-loaded.eu/2007/09/15/use-wget-or-curl-to-download-from-rapidshare-premium/</link>
		<comments>http://www.g-loaded.eu/2007/09/15/use-wget-or-curl-to-download-from-rapidshare-premium/#comments</comments>
		<pubDate>Sat, 15 Sep 2007 08:55:17 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/2007/09/15/use-wget-or-curl-to-download-from-rapidshare-premium/</guid>
		<description><![CDATA[This article describes how to use the command line download managers wget and curl in order to download files from your Rapidshare Premium account.]]></description>
			<content:encoded><![CDATA[<p>The last days I needed to download a bunch of medical videos which have been uploaded to RapidShare by many other people. Although RapidShare (and all the other 1-click file-hosting services) is very convenient, it has some strict rules for free accounts, for example a guest has to wait for 120 seconds per 1 MB of downloaded data and &#8211; to make it worse &#8211; no download managers are allowed. Since &#8220;waiting&#8221; is not a game I like and since I intended to use either <a href="http://www.gnu.org/software/wget/">wget</a> or <a href="http://curl.haxx.se/">curl</a> to download the files, I decided to sign up for a <a href="http://www.rapidshare.com/">RapidShare</a> Premium account and then figure out how to use the aforementioned tools. Fortunately, registered users are permitted to use download managers and, as you will read in the following article, the Linux command line downloaders work flawlessly with a Premier account.<br />
<span id="more-443"></span></p>
<h4>Theory</h4>
<p>Rapidshare uses cookie-based authentication. This means that every time you log into the service, a cookie containing information which identifies you as a registered user is stored in your browser&#8217;s cookie cache. Both <code>wget</code> and <code>curl</code> support saving and loading cookies, so before using them to download any files, you should save such a cookie. Having done this, then the only required action in order download from RapidShare is to load the cookie, so that wget or curl can use it to authenticate you on the RapidShare server. This is pretty much the same you would do with a graphical download manager. The difference now is that you do it on the command line.</p>
<p>Below you will find examples about how to perform these actions using both wget and curl.</p>
<p><strong>IMPORTANT</strong>: Please note that in order to use these command-line utilities or any other download managers with RapidShare, you will have to check the <strong>Direct Downloads option</strong> in your account&#8217;s <strong>options page</strong>.</p>
<h4>Save your RapidShare Premium Account Cookie</h4>
<p>Saving your RapidShare cookie is a procedure that needs to be done <strong>once</strong>.</p>
<p>The login page is located at:</p>
<pre class="codesnp">https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi</pre>
<p>The login form requires two fields: <strong>login</strong> and <strong>password</strong>. These are pretty self-explanatory.</p>
<p>In the following examples, the RapidShare username is shown as <strong>USERNAME</strong> and the password as <strong>PASSWORD</strong>.</p>
<h5>Using wget</h5>
<p>In order to save your cookie using wget, run the following:</p>
<pre class="console">
wget \
    --save-cookies ~/.cookies/rapidshare \
    --post-data "login=USERNAME&#038;password=PASSWORD" \
    -O - \
    https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi \
    > /dev/null
</pre>
<p><strong>&#8211;save-cookies</strong> : Saves the cookie to a file called <code>rapidshare</code> under the <code>~/.cookies</code> directory (let&#8217;s assume that you store your cookies there)<br />
<strong>&#8211;post-data</strong> : is the POST payload of the request. In other words it contains the data you would enter in the login form.<br />
<strong>-O -</strong> : downloads the HTML data to the standard output. Since the above command is run only in order to obtain the cookie, this option prints the HTML data to stdout (Standard Output) and then discards it by redirecting stdout to <code>/dev/null</code>. If you don&#8217;t do this, wget will save the HTML data in a file called <code>premiumzone.cgi</code> in the current directory. This is just the Rapidshare HTML page, which is absolutely not needed.</p>
<h5>Using curl</h5>
<p>In order to save your cookie using curl, run the following:</p>
<pre class="console">
curl \
    --cookie-jar ~/.cookies/rapidshare \
    --data "login=USERNAME&#038;password=PASSWORD" \
    https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi \
    > /dev/null
</pre>
<p><strong>&#8211;cookie-jar</strong> : Saves the cookie to a file called <code>rapidshare</code> under the <code>~/.cookies</code> directory (it has been assumed previously that cookies are stored there)<br />
<strong>&#8211;data</strong> : contains the data you would enter in the login form.<br />
Curl prints the downloaded page data to stdout by default. This is discarded by sending it to <code>/dev/null</code>.</p>
<h4>Download files using your RapidShare Premium Account Cookie</h4>
<p>Having saved your cookie, downloading files from RapidShare is as easy as telling wget/curl to load the cookie everytime you use them to download a file.</p>
<h5>Downloading with wget</h5>
<p>In order to download a file with wget, run the following:</p>
<pre class="console">
wget -c --load-cookies ~/.cookies/rapidshare &lt;URL&gt;
</pre>
<p><strong>-c </strong>: this is used in order to resume downloading of the file if it already exists in the current directory and is incomplete.<br />
<strong>&#8211;load-cookies</strong> : loads your cookie.</p>
<h5>Downloading with curl</h5>
<p>In the same manner, in order to download a file with curl, run the following:</p>
<pre class="console">
curl -L -O --cookie ~/.cookies/rapidshare &lt;URL&gt;
</pre>
<p><strong>-L</strong> : Follows all redirections until the final destination page is found. This switch is almost always required as curl won&#8217;t follow redirects by default (read about how to check the server <a href="http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/">http headers</a> with curl).<br />
<strong>-O</strong> : By using this switch you instruct curl to save the downloaded data to a file in the current directory. The filename of the remote file is used. This switch is also required or else curl will print the data to stdout, which is something you won&#8217;t probably like.<br />
<strong>&#8211;cookie</strong> : loads your Rapidshare account&#8217;s cookie.</p>
<h4>Setting up a Download Server</h4>
<p>Although most users would be satisfied with the above, I wouldn&#8217;t be surprised if you would want to go a bit further and try to setup a little service for your downloading pleasure. Here is a very primitive implementation of such a service. All you will need is standard command line tools.</p>
<p>This primitive server consists of the following:</p>
<ol>
<li>A <a href="http://en.wikipedia.org/wiki/Named_pipe">named pipe</a>, called &#8220;<strong>dlbasket</strong>&#8220;. You will feed the server with URLs through this pipe. Another approach would be to use a listening TCP socket with <a href="http://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples/">NetCat</a>.</li>
<li>A script, which, among others, contains the main server loop. This loop reads one URL at a time from dlbasket and starts a wget/curl process in order to download the file. If dlbasket is empty, the server should just stay there waiting.</li>
</ol>
<p>So, in short, the service would be the following:</p>
<pre class="codesnp">
cat &lt;&gt; dlbasket | ( while ... done )
</pre>
<p>All credit for the &#8220;<strong>cat &lt;&gt; dlbasket |</strong>&#8221; magic goes to <strong><em>Zart</em></strong>, who kindly helped me out at the #fedora IRC channel.</p>
<p>So, let&#8217;s create that service. The following assume that a user named &#8220;<strong>downloader</strong>&#8221; exists in the system and the home directory is <code>/var/lib/downloader/</code>. Of course you can set this up as you like, but make sure you adjust the following commands and the script&#8217;s configuration options accordingly.</p>
<p>First, create the named pipe:</p>
<pre class="console">
mkfifo -m 0700 /var/lib/downloader/dlbasket
</pre>
<p>If it does not exist, create a <code>bin</code> directory in the user&#8217;s home:</p>
<pre class="console">
mkdir -p /var/lib/downloader/bin
</pre>
<p>Also, create a directory where the downloaded files will be saved:</p>
<pre class="console">
mkdir -p /var/lib/downloader/downloads
</pre>
<p>The following is a quick and dirty script I wrote which actually implements the service. Save it as <strong>rsgetd.sh</strong> inside the user&#8217;s <code>bin</code> directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/env bash  </span>
&nbsp;
<span style="color: #666666; font-style: italic;">#  rsgetd.sh - Download Service</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#  Version 0.3</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#  Copyright (C) 2007 George Notaras (http://www.g-loaded.eu/)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#  it under the terms of the GNU General Public License version 2 as</span>
<span style="color: #666666; font-style: italic;">#  published by the Free Software Foundation.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#  This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#  but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#  GNU General Public License for more details.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Special thanks to 'Zart' from the #fedora channel on FreeNode</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># v0.3 - Oct 31 2009:</span>
<span style="color: #666666; font-style: italic;"># - corrected error: &quot;./bin/rsgetd.sh: line 37: [: argument expected&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># CONFIG START </span>
<span style="color: #007800;">HOMEDIR</span>=<span style="color: #ff0000;">&quot;/var/lib/downloader&quot;</span>
<span style="color: #007800;">DLBASKET</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOMEDIR</span>/dlbasket&quot;</span>
<span style="color: #007800;">DLDIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOMEDIR</span>/downloads/&quot;</span>
<span style="color: #007800;">LOGFILE</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOMEDIR</span>/.downloads_log&quot;</span>
<span style="color: #007800;">CACHEFILE</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOMEDIR</span>/.downloads_cache&quot;</span>
<span style="color: #007800;">LIMIT</span>=<span style="color: #ff0000;">&quot;25k&quot;</span>
<span style="color: #007800;">WGETBIN</span>=<span style="color: #ff0000;">&quot;/usr/bin/wget&quot;</span>
<span style="color: #666666; font-style: italic;"># Rapidshare Login Cookie  </span>
<span style="color: #007800;">RSCOOKIE</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOMEDIR</span>/cookies/.rapidshare&quot;</span>
<span style="color: #666666; font-style: italic;"># CONFIG END</span>
&nbsp;
<span style="color: #007800;">DATETIME</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`date '+%Y-%m-%d %H:%M:%S'`</span>&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&amp;</span>lt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$DLBASKET</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> url ; <span style="color: #000000; font-weight: bold;">do</span>
                <span style="color: #666666; font-style: italic;"># First, check the cache if the file has been already downloaded</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CACHEFILE</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(grep -i $(basename $url)</span> <span style="color: #007800;">$CACHEFILE</span>)&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
                       <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DATETIME</span> File exists in cache. Already downloaded - Skipping: <span style="color: #007800;">$url</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
                <span style="color: #000000; font-weight: bold;">else</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DATETIME</span> Starting with rate <span style="color: #007800;">$LIMIT</span>/s: <span style="color: #007800;">$url</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
                        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">expr</span> match <span style="color: #ff0000;">&quot;<span style="color: #007800;">$url</span>&quot;</span> <span style="color: #ff0000;">'[rapidshare.com]'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
                                <span style="color: #666666; font-style: italic;"># If it is a Rapidshare.com link, load the RS cookie </span>
                                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;RAPIDSHARE LINK&quot;</span>
                                <span style="color: #007800;">$WGETBIN</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">--limit-rate</span>=<span style="color: #007800;">$LIMIT</span> <span style="color: #660033;">--directory-prefix</span>=<span style="color: #007800;">$DLDIR</span> <span style="color: #660033;">--load-cookies</span> <span style="color: #007800;">$RSCOOKIE</span> <span style="color: #007800;">$url</span>
                        <span style="color: #000000; font-weight: bold;">else</span>
                                <span style="color: #007800;">$WGETBIN</span> <span style="color: #660033;">-c</span> <span style="color: #660033;">--limit-rate</span>=<span style="color: #007800;">$LIMIT</span> <span style="color: #660033;">--directory-prefix</span>=<span style="color: #007800;">$DLDIR</span> <span style="color: #007800;">$url</span>
                        <span style="color: #000000; font-weight: bold;">fi</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DATETIME</span> Finished: <span style="color: #007800;">$url</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$url</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$CACHEFILE</span>
                <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">done</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>As you might have already noticed, two extra files are created inside the home directory: <code>.downloads_cache</code> and <code>.downloads_log</code>. The first contains a list of all the urls that have been downloaded. Each new download is checked against this list, so that the particular URL is not processed if the file has already been downloaded. The latter file is a usual logfile stating the start and end times of each download. Feel free to adjust the script to your needs.</p>
<p>Here is some info about how you should start the service:</p>
<p><strong>-1-</strong> You can simply start the script as a background process and then feed URLs to it. For example:</p>
<pre class="console">
rsgetd.sh &#038;
echo "&lt;URL&gt;" &gt; /var/lib/downloader/dlbasket
</pre>
<p><strong>-2-</strong> Use <a href="http://www.gnu.org/software/screen/">screen</a> in order to run the script in the background but still be able to see its output by connecting to a screen session. Although this is not a screen howto, here is an example:</p>
<p>Create a new screen session and attach to it:</p>
<pre class="console">
screen -S rs_downloads
</pre>
<p>While being in the session, run rsgetd.sh</p>
<pre class="console">
rsgetd.sh
</pre>
<p>From another terminal feed the download basket (dlbasket) with urls:</p>
<pre class="console">
echo "&lt;URL&gt;" &gt; /var/lib/downloader/dlbasket
cat url_list.txt &gt; /var/lib/downloader/dlbasket
</pre>
<p>Watch the files in the screen window as they are being downloaded.</p>
<p>Detach from the screen session by hitting the following:</p>
<pre class="codesnp">
Ctrl-a   d
</pre>
<p>Re-attach to the session by running:</p>
<pre class="console">
screen -r
</pre>
<p>Note that you do not need to be attached to the screen session in order to add URLs.</p>
<h5>Feeding the basket with URLs remotely</h5>
<p>Assuming that a SSH server is running on the machine that runs rsgetd.sh, you can feed URLs to it by running the following from a remote machine:</p>
<pre class="console">
ssh downloader@server.example.org cat \&gt; /var/lib/downloader/dlbasket
</pre>
<p>Note that the <strong>&gt;</strong> needs to be escaped so that it is considered as part of the command that will be executed on the remote server.</p>
<p>Now, feel free to <strong>add</strong> as many <strong>URLs</strong> as you like. After you hit the <strong>[Enter]</strong> key the url will be added to the download queue. When you are finished, just press <strong>Ctrl-D</strong> to end the URL submission.</p>
<h4>Conclusion</h4>
<p>This article provides all the information you need in order to use wget or curl to download files from your RapidShare Premium account. Also, information on how to set up a service that will assist you in order to commence downloads on your home server from a remote location has been covered.</p>
<p>The same information applies in all cases that wget and curl need to be used with websites that use cookie-based authentication.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2007/09/15/use-wget-or-curl-to-download-from-rapidshare-premium/">Use wget or curl to download from RapidShare Premium</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2006/10/06/check-server-http-headers-with-curl/" rel="bookmark">Check Server HTTP Headers with CURL</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/mass-download/" rel="bookmark">Mass download</a></li>
<li><a href="http://www.g-loaded.eu/2006/01/06/partition-images-with-partimage-and-partimaged/" rel="bookmark">Partition images with Partimage and Partimaged</a></li>
<li><a href="http://www.g-loaded.eu/2005/10/13/http-headers/" rel="bookmark">HTTP headers</a></li>
<li><a href="http://www.g-loaded.eu/2007/08/06/file-and-directory-diff-in-color-in-midnight-commander/" rel="bookmark">File and Directory diff in color in Midnight Commander</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2007/09/15/use-wget-or-curl-to-download-from-rapidshare-premium/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Mailing List Manager</title>
		<link>http://www.g-loaded.eu/2007/08/20/mailing-list-manager/</link>
		<comments>http://www.g-loaded.eu/2007/08/20/mailing-list-manager/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 13:29:51 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Review]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/2007/08/20/mailing-list-manager/</guid>
		<description><![CDATA[If you are looking for a lean, mean mailing list manager (MLM), look no further. The software you are looking for is called: the Minimalist. Despite the fact that the Minimalist is just a Perl script with a filesize of 70Kb, it is a full featured MLM which will satisfy almost all users. Do not [...]]]></description>
			<content:encoded><![CDATA[<p>If you are looking for a lean, mean mailing list manager (<strong>MLM</strong>), look no further. The software you are looking for is called: the <a href="http://www.mml.org.ua/">Minimalist</a>. Despite the fact that the Minimalist is just a Perl script with a filesize of 70Kb, it is a full featured MLM which will satisfy almost all users. Do not expect to find any extra functionality in that script like web interfaces, email archivers, etc. The Minimalist has been designed to serve one purpose: <em>manage mailing lists</em>; that is supporting some commands which are sent to the program by email and taking the relevant actions upon their arrival. The mailing list archives can be converted to HTML pages by using one of the popular email archivers: <a href="http://www.mhonarc.org/">MHonArc</a> and <a href="http://www.hypermail-project.org/">HyperMail</a> (there is also <em>Pipermail</em> which is included in the <a href="http://www.gnu.org/software/mailman/">Mailman</a> suite).</p>
<p>I&#8217;ve been experimenting with the Minimalist for the last days and all I can say is that this software <em>Just Works</em>&trade; &#8230; and I like it when software works! Actually, I liked it so much that I have devoted a significant amount of time in writing a program that acts as a bridge between the Minimalist&#8217;s mailing list archives and MHonArc. This program (a MHonArc wrapper actually), which also includes a set of <em>resource files</em> in order to heavily customize MHonArc&#8217;s HTML output (in an attempt to be like the popular Mailman web archives), is called BenzinArc (<em>Benzin Archiver</em>) and can be used both as a cron job and as a standalone application. BenzinArc is still work in progress. No code has been released yet. An overview of the HTML version of the <em>CodeTRAX Mailing List Archives</em> is available. Currently, only one read-only mailing list, <strong>codetrax-bugs</strong>, exists. This is a dedicated list to the bug reports of all projects hosted by <a href="http://www.codetrax.org/">CodeTRAX</a>, but it is enough to serve as an example.</p>
<p>All this mailing-list-related stuff has kept me away from working on the <strong>0.7.1</strong> release of the <a href="http://www.codetrax.org/projects/traxauth">TraxAuth Account System</a>, but I assume all that was absolutely necessary. Although my free time will be very little in the upcoming weeks, I guess I will be able to release a new version of <em>TraxAuth</em> and the first public test release of <em>BenzinArc</em>.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2007/08/20/mailing-list-manager/">Mailing List Manager</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2007/03/05/organizing-mailing-list-messages-with-evolution/" rel="bookmark">Organizing Mailing List messages with Evolution</a></li>
<li><a href="http://www.g-loaded.eu/2007/08/17/next-time-come-prepared/" rel="bookmark">Next time, come prepared</a></li>
<li><a href="http://www.g-loaded.eu/2007/08/09/traxauth/" rel="bookmark">TraxAuth</a></li>
<li><a href="http://www.g-loaded.eu/2009/12/09/mozilla-thunderbird-3-is-out/" rel="bookmark">Mozilla Thunderbird 3 is out!</a></li>
<li><a href="http://www.g-loaded.eu/2006/02/23/blog-freeze/" rel="bookmark">Blog Freeze</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2007/08/20/mailing-list-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>rtorstat &#8211; a simple rTorrent status web page generator</title>
		<link>http://www.g-loaded.eu/2007/06/23/rtorstat-a-simple-rtorrent-status-web-page-generator/</link>
		<comments>http://www.g-loaded.eu/2007/06/23/rtorstat-a-simple-rtorrent-status-web-page-generator/#comments</comments>
		<pubDate>Sat, 23 Jun 2007 11:35:44 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Bittorrent]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[rTorrent]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/2007/06/23/rtorstat-a-simple-rtorrent-status-web-page-generator/</guid>
		<description><![CDATA[rtorstat is a simple web page generator, written in Python, which shows status information about the rTorrent bittorrent client. This makes it possible to quickly have an overview of your torrent list from a remote location, without having to log into the remote machine that actually runs rTorrent.]]></description>
			<content:encoded><![CDATA[<p><strong>rtorstat</strong> is a simple <em>web page generator</em>, written in <a href="http://www.python.org/">Python</a>, which shows status information about the <a href="http://libtorrent.rakshasa.no/">rTorrent</a> bittorrent client. This makes it possible to quickly have an overview of your torrent list from a remote location, without having to log into the remote machine that actually runs rTorrent.<br />
<span id="more-408"></span><br />
The script can operate in two modes:</p>
<ul>
<li>Run through <strong>cron</strong> at predefined intervals. In this case it reads the saved <em>rtorrent session data</em>, creates a <strong>summary</strong> about the loaded torrent files status and <strong>prints</strong> the HTML code to <strong>stdout</strong>, which can then be <strong>redirected to a file</strong> and thus be made publicly available by a web server.</li>
<li>Run as a <strong>CGI</strong> script, which makes it possible to <strong>dynamically generate the HTML page</strong> on-demand. This method, compared to running rtorstat through cron at short pre-defined intervals, has the advantage of <em>limiting system resource waste</em> by parsing the session data only when a user runs the CGI script through the web browser. Also, depending on your rtorrent settings, the displayed information is usually more current than that of the HTML page generated through cron, unless cron runs the script very often.</li>
</ul>
<p>rtorstat does not support or will never support any kind of remote rTorrent administration. It is not supposed to be a web-based rtorrent frontend, but, as the title says, a <em>simple status page generator</em> (status web interface).</p>
<h4>Requirements</h4>
<p>rtorstat is not dependency-free. Here is the list of the required software in order to run rtorstat:</p>
<ul>
<li><a href="http://www.python.org/">Python</a></li>
<li><a href="http://libtorrent.rakshasa.no/">rTorrent</a> (configured to save session data &#8211; <em>see below</em>)</li>
<li>The file &#8220;<em>bencode.py</em>&#8220;, part of the official <a href="http://www.bittorrent.com/">Bittorrent</a> client (<em>Mainline</em>) distribution, has been included in the <strong>rtorstat</strong> distribution package, so the Mainline Bittorrent client is <strong>no longer a dependency for rtorstat</strong>.</li>
</ul>
<h4>rTorrent Configuration</h4>
<p><em>rtorstat</em> needs to read the <strong>torrent session data</strong>, so rTorrent needs to be configured to save this information to a pre-defined directory. The following shows all the session-data specific configuration rTorrent (<code>.rtorrent.rc</code>) options:</p>
<pre class="codesnp">

# Sets the directory where session data files are stored
session = /opt/bittorrent/sessiondata

# Keeps session data files even if torrent has finished
session_on_completion = yes

# Not really required, but recommended - see rtorrent(1) man page
session_lock = yes

# Setup A: Run through CRON
# Save session data every 5 mins, with a 4 min offset
schedule = session_save,240,300,session_save=

# Setup B: Run as a CGI
# Save session data every 300 seconds
# (This is an example value. Setting it to a lower value is highly recommended)
#schedule = session_save,300,300,session_save=
</pre>
<p>The last directive (<code>schedule</code>) instructs rtorrent to save session data at the specified interval.</p>
<h4>Usage</h4>
<p>rtorstat can be run through cron or as a CGI script. Running it as a CGI is the preferred way of running it as the parsing of the session data and the HTML page generation take place dynamically only when you visit the web page. This leads to wasting less system resources.</p>
<h5>Running rtorstat through cron</h5>
<p>No special <strong>installation</strong> is needed as the location of <code>rtorstat.py</code> can be set within the <strong>cron</strong> job. Just make sure that the file <code>bencode.py</code> exists in the same directory as rtorstat.py.</p>
<p>rtorstat requires one <strong>argument</strong>; that is the <strong>path to the directory</strong> where the session data is saved:</p>
<pre class="console">$ python rtorstat.py /opt/bittorrent/sessiondata/</pre>
<p>Having parsed the session data files and having created the summary, the HTML code is printed to <strong>stdout</strong>, from where it can be redirected to a html file. For example:</p>
<pre class="console">$ python rtorstat.py /opt/bittorrent/sessiondata/ > /var/www/index.html</pre>
<p>rtorstat is supposed to be run through cron at regular intervals. In the example configuration above (<em>Setup A</em>), rtorrent saves the session data every 5 minutes (300 sec), so rtorstat needs to be run at the <strong>same interval</strong> through cron. The 4 min offset (240 sec) that had been set in the rtorrent scheduler serves so that there is good timing between rTorrent saving the session data and rtorstat parsing it.</p>
<p>Such a cron job would be:</p>
<pre class="codesnp">*/5 * * * *   root python /path/to/rtorstat.py /opt/bittorrent/sessiondata/ > /var/www/index.html</pre>
<p>rtorstat will parse the session data files, for example, at 00:05, 00:10 etc.</p>
<p>Having adjusted the paths according to your configuration, <strong>save</strong> the above <strong>cronjob</strong> to a file inside the <code>/etc/cron.d/</code> directory and you are set.</p>
<h5>Running rtorstat as a CGI script</h5>
<p>In this case, you need to place 3 files in your cgi-bin: rtorstat.py, rtorstat.cgi and bencode.py.</p>
<p>Apart from the rtorrent configuration, it is required to set the path of the directory where rtorrent saves session data in rtorstat.cgi. So, open rtorstat.cgi in your favourite text editor and fill-in the required information:</p>
<pre class="codesnp">
session_dir = "/path/to/rtorrent/session/dir/"
</pre>
<p>Now, you can visit the web page http://yourdomain.example.org/cgi-bin/rtorstat.cgi</p>
<p>Setting up a scriptaliased directory is covered by your web server&#8217;s documentation and is outside of the scope of this document.</p>
<h4>Security</h4>
<p>rtorstat generates a HTML page which is made publicly available through a web server (most probably). Therefore it is your responsibility to secure this location using any of your web server&#8217;s access control methods.</p>
<h4>License</h4>
<p>This project is released under the terms of the <a href="http://www.codetrax.org/licenses/ApacheLicenseV2">Apache License version 2</a>.</p>
<h4>Download</h4>
<p>All versions of the software, including the latest stable release, are available from the development web site&#8217;s <a href="http://www.codetrax.org/projects/rtorstat/files">download area</a>.</p>
<h4>Donate</h4>
<p>This software is released as <strong>free software</strong>. Nevertheless, its development requires time and effort. A small donation, as a sign of appreciation of the effort, is welcome. Please, use the following button to visit the <em>Donations</em> page. Thank you.</p>
<p><a href="http://www.g-loaded.eu/about/donate" title="Donate"><img src="/images/donations_button.png" alt="Donations Button" /></a></p>
<h4>Support</h4>
<p>This software is released as <em>free software</em> without any warranties or official support. You can still get first class <strong>support</strong> from the <a href="http://www.codetrax.org/projects/rtorstat/boards">community of users</a>.</p>
<h4>Bugs and Feature Requests</h4>
<p>Found a bug? Want to suggest a new feature for the upcoming release? Feel free to file your requests in the <a href="http://www.codetrax.org/projects/rtorstat/issues">issue database</a> on the <a href="http://www.codetrax.org/projects/rtorstat">development website</a>.</p>
<h4>Things to consider</h4>
<p>It has been mentioned before, but here it goes again:</p>
<p>Note that by making the rtorrent status page publicly available through a web server, the world will know what you download at any time. It is your exclusive responsibility to keep this page private, if this is what you really want. This piece of information is of course beyond the scope of this article.</p>
<p>This script was written in a quick and dirty way. If you encounter any bugs, please notify me through the <em>g-loaded forums</em> and I will get back to you when I have the time.</p>
<p>Last, but not least, if you improve the looks, consider <a href="http://www.g-loaded.eu/about/contributions/">contributing</a> back your <strong>string template</strong>.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2007/06/23/rtorstat-a-simple-rtorrent-status-web-page-generator/">rtorstat &#8211; a simple rTorrent status web page generator</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2006/09/23/use-python-to-get-the-web-page-data-in-epiphany/" rel="bookmark">Use Python to get the web page data in Epiphany</a></li>
<li><a href="http://www.g-loaded.eu/2006/05/04/write-a-man-page/" rel="bookmark">Write A Man Page</a></li>
<li><a href="http://www.g-loaded.eu/2008/05/09/remove-generator-meta-tag-wordpress-plugin/" rel="bookmark">Remove-Generator-Meta-Tag WordPress Plugin</a></li>
<li><a href="http://www.g-loaded.eu/2007/03/05/print-a-man-page/" rel="bookmark">Print a Man Page</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/mass-download/" rel="bookmark">Mass download</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2007/06/23/rtorstat-a-simple-rtorrent-status-web-page-generator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Error when using old run/bin installers under Linux</title>
		<link>http://www.g-loaded.eu/2007/02/25/error-when-using-old-runbin-installers-under-linux/</link>
		<comments>http://www.g-loaded.eu/2007/02/25/error-when-using-old-runbin-installers-under-linux/#comments</comments>
		<pubDate>Sun, 25 Feb 2007 12:00:35 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[Resolved]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/2007/02/25/error-when-using-old-runbin-installers-under-linux/</guid>
		<description><![CDATA[I guess that every single *nix user, at least once, has run across files with the *.run or *.bin extensions. These scripts are usually software installers and are widely used to distribute, but not limited to, proprietary software to the Unix world. Examples are the popular NVidia or ATI display drivers for Linux and other [...]]]></description>
			<content:encoded><![CDATA[<p>I guess that every single *nix user, at least once, has run across files with the <code>*.run</code> or <code>*.bin</code> extensions. These scripts are usually software installers and are widely used to distribute, but not limited to, proprietary software to the Unix world. Examples are the popular <a href="http://www.nvidia.com/object/unix.html">NVidia</a> or <a href="http://ati.amd.com/support/driver.html">ATI</a> display drivers for Linux and other operating systems, the <a href="http://java.com/en/download/linux_manual.jsp">Sun Java Runtime Environment</a> etc. Recently, I encountered some issues when trying to use such installers.<br />
<span id="more-329"></span><br />
But first, some information about these scripts (installers). These are created with the <a href="http://www.megastep.org/makeself/">makeself</a> shell script, which actually creates self-extractable <code>tar.gz</code> archives. When launched, the installer does an archive integrity check and then extracts the included software to the desired location and performs all the programmed actions in order to make the installed software functional within the operating system.</p>
<p>Recently, I had to install the <a href="http://www.glub.com/products/secureftp/download.shtml">SecureFTP</a> ftp client for linux, but the script errored out with some strange messages like not being able to uncompress the archive or about not being able to verify the archive&#8217;s checksum or about wrong command line parameters used in some command calls internally. This had happened in the past too, when I wanted to install the good old game <a href="http://www.unrealtournament.com/utgoty/index.html">Unreal Tournament</a> (1999) so to revive some good memories. ;-)</p>
<p>Here are some of the weird error messages:</p>
<pre class="codesnp">
tail: cannot open `+187' for reading: No such file or directory

gunzip: stdin: not in gzip format

Verifying archive integrity...tail: cannot open `+6' for reading: No such file or directory
Error in check sums 1237260170 2341625838
</pre>
<p>As stated at the makeself website, archives created with Makeself older than v2.1.2 were using an old syntax for the <code>head</code> and <code>tail</code> Unix commands and there are problems uncompressing the included software.</p>
<p>In order to resolve this issue and make the installer &#8220;assume&#8221; that you use an old GNU/Linux version, you should export the following environment variable before using the installer:</p>
<pre class="console">export _POSIX2_VERSION=199209</pre>
<p>After you finish installing the software, delete that ENV variable:</p>
<pre class="console">unset _POSIX2_VERSION</pre>
<p>It took me a significant amount of time to learn about this workaround and, basically, I discovered it while searching for the software that creates these self-installing archives.</p>
<p>Hope this tip helps someone out there.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2007/02/25/error-when-using-old-runbin-installers-under-linux/">Error when using old run/bin installers under Linux</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2007/07/29/when-it-comes-to-error-messages/" rel="bookmark">When it comes to error messages&#8230;</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/" rel="bookmark">Script for Apache Error Report</a></li>
<li><a href="http://www.g-loaded.eu/2007/12/07/email-notifications-from-a-linux-system/" rel="bookmark">Email Notifications from a Linux System</a></li>
<li><a href="http://www.g-loaded.eu/2009/03/03/burning-a-dvd-still-an-adventure-on-gnulinux/" rel="bookmark">Burning a DVD still an adventure on GNU/Linux</a></li>
<li><a href="http://www.g-loaded.eu/2007/08/20/mailing-list-manager/" rel="bookmark">Mailing List Manager</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2007/02/25/error-when-using-old-runbin-installers-under-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>SELinux audit reports script</title>
		<link>http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/</link>
		<comments>http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/#comments</comments>
		<pubDate>Wed, 20 Dec 2006 09:52:53 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Cron]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[SELinux]]></category>

		<guid isPermaLink="false">http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/</guid>
		<description><![CDATA[Those who use a SELinux enabled distribution &#8211; more specifically those who have set the SELinux security layer to enforcing mode &#8211; will most probably know about the auditd daemon (part of the audit package in Fedora Core). By default, all SELinux messages are recorded to the syslog, but when auditd is running, then all [...]]]></description>
			<content:encoded><![CDATA[<p>Those who use a SELinux enabled distribution &#8211; more specifically those who have set the SELinux security layer to <strong>enforcing</strong> mode &#8211; will most probably know about the <strong>auditd</strong> daemon (part of the <strong>audit</strong> package in Fedora Core). By default, all SELinux messages are recorded to the syslog, but when auditd is running, then all messages are kept in <code>/var/log/audit/audit.log</code>.<br />
<span id="more-296"></span><br />
The audit package, apart from the audit daemon, includes some very interesting utilities, <strong>aureport</strong> and <strong>ausearch</strong>, which are two great assistants in the procedure of locating the events that need investigation in the endless log files. <code>aureport</code> produces the report it has been asked for and <code>ausearch</code> is used to search the logs for a given event number. Enough said, now on to the script.</p>
<p><code>aureport</code> has a shortcoming. It can only display one report at a time. So, in order to have daily SELinux reports in our inbox aureport needs to be called several times from within a cron job. This is why <strong>aureportgen.py</strong> was written. It can be configured to execute aureport several times collecting the pre-defined reports for a given period of time and then print a concatenation of these reports to the stdout.</p>
<h4>Configuration</h4>
<p>Open the <code>aureportgen.py</code> script in a text editor and scroll down to the configuration section. The available options are:</p>
<p>The path to the aureport executable:</p>
<pre class="codesnp">aureportpath = "/sbin/aureport"</pre>
<p>The list of the reports to collect:</p>
<pre class="codesnp">reports = ["a", "mf", "ms", "lf", "ls"]</pre>
<p>The line above might be a little cryptic so here is the convention on how to specify the report names:</p>
<ol>
<li>Each report name may consist of up to <em>two letters</em>. The <strong>first</strong>, which is mandatory, specifies the report type and the <strong>second</strong>, which is optional, specifies whether a successes or a failures report will be returned.</li>
<li>All the aureport command line switches that specify a report type can be used as the first letter.</li>
<li>Either the letter &#8220;<strong>f</strong>&#8221; or &#8220;<strong>s</strong>&#8221; can be used as the second letter to indicate a success-only or failure-only report.</li>
<li>If the second letter is omitted, then a report that contains both successful and failed events is returned.</li>
</ol>
<p>By using the configuration above, the following reports will be returned:</p>
<ol>
<li>AVC denials (successes or failures not applicable to this report)</li>
<li>Account modification failures</li>
<li>Account modification successes</li>
<li>Login failures</li>
<li>Login successes</li>
</ol>
<h4>Usage</h4>
<p>This script was written in order to be called from within a cron job. It is mandatory to specify the number of days in the past the reports will be generated for. This is done with the <strong>&#8211;days</strong> command line option.</p>
<p>An example daily cron script is listed below:</p>
<pre class="codesnp">
#! /bin/bash

python /path/to/aureportgen.py --days 1 | mail -s "SELinux Reports by aureport" root

exit 0
</pre>
<p>The same as a cronjob would be:</p>
<pre class="codesnp">
0 0 * * *    root    python /path/to/aureportgen.py --days 1 | mail -s "SELinux Reports by aureport" root
</pre>
<p>This will scan the audit logs and the pre-defined reports will be generated for the last 24 hours. The output will be emailed to root.</p>
<p><strong>WARNING</strong>: It should be possible to run this script directly on the CLI and have multiple reports displayed in the standard output, but if the login shell&#8217;s locale is different than the crn job&#8217;s, then there could be a problem. In such cases, you will still be able to run it from the CLI without errors by setting the extra configuration option <code>fix_date</code> to <strong>True</strong>:</p>
<pre class="codesnp">fix_date = True</pre>
<h4>License</h4>
<p>This project is released under the terms of the <a href="http://www.g-loaded.eu/licenses/GPL">GNU General Public License</a>.</p>
<h4>Download</h4>
<p>You can download this script from the following link:<br />
<a href="http://www.g-loaded.eu/packages/aureportgen/aureportgen-0.1.tar.gz">aureportgen-0.1.tar.gz</a></p>
<p>Note that this is an alpha version, it is released without any warranties or support.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/">SELinux audit reports script</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>


<h4>Related Articles</h4>

<ul><li><a href="http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/" rel="bookmark">How to integrate seaudit-report in logwatch</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/" rel="bookmark">Script for Apache Error Report</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/30/selinux-setenforce-mode/" rel="bookmark">Using setenforce to switch SELinux mode wisely</a></li>
<li><a href="http://www.g-loaded.eu/2005/12/15/get-my-kernel-headers-script/" rel="bookmark">Get my kernel headers script</a></li>
<li><a href="http://www.g-loaded.eu/2006/05/06/a-useful-script/" rel="bookmark">A Useful Script</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>
