<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>1000umbrellas.com &#187; cron</title>
	<atom:link href="http://1000umbrellas.com/tag/cron/feed" rel="self" type="application/rss+xml" />
	<link>http://1000umbrellas.com</link>
	<description>Michael Descy&#039;s Personal Website</description>
	<lastBuildDate>Fri, 15 Jul 2011 02:06:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<atom:link rel='hub' href='http://1000umbrellas.com/?pushpress=hub'/>
		<item>
		<title>How to Monitor Services on Ubuntu Lucid Lynx Using Monit</title>
		<link>http://1000umbrellas.com/2010/10/27/how-to-monitor-services-on-ubuntu-lucid-lynx-using-monit</link>
		<comments>http://1000umbrellas.com/2010/10/27/how-to-monitor-services-on-ubuntu-lucid-lynx-using-monit#comments</comments>
		<pubDate>Wed, 27 Oct 2010 12:00:52 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[lucid lynx]]></category>
		<category><![CDATA[mediatomb]]></category>
		<category><![CDATA[monit]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pid file]]></category>
		<category><![CDATA[restart]]></category>
		<category><![CDATA[samba]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[sshd]]></category>
		<category><![CDATA[transmission-daemon]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://1000umbrellas.com/?p=1109</guid>
		<description><![CDATA[Even though my Ubuntu Lucid Lynx media server runs pretty solidly, I like to monitor it periodically using SSH and command line tools. Some of my favorites are w, htop, ps, bwm-ng, and nmap. After rebuilding my server, I decided to install some lightweight system monitoring tools that exposed themselves via a web interface, so [...]]]></description>
			<content:encoded><![CDATA[<p>Even though my Ubuntu Lucid Lynx media server runs pretty solidly, I like to monitor it periodically using SSH and command line tools. Some of my favorites are <a href="http://en.wikipedia.org/wiki/W_(Unix)" target="_blank">w</a>, <a href="http://htop.sourceforge.net/" target="_blank">htop</a>, <a href="http://en.wikipedia.org/wiki/Ps_(Unix)" target="_blank">ps</a>, <a href="http://sourceforge.net/projects/bwmng/" target="_blank">bwm-ng</a>, and <a href="http://www.nmap.org/" target="_blank">nmap</a>. After rebuilding my server, I decided to install some lightweight system monitoring tools that exposed themselves via a web interface, so I could check up on my server more quickly. The FLOSS utility <a href="http://mmonit.com/monit/" target="_blank">Monit</a> fit the bill for point-in-time monitoring.</p>
<p>Monit is a utility that you can set up to monitor your server’s processes and files, alert you to problems, restart stopped services, and present a web interface to display the server’s current status. I suspect most administrators would configure it to email them when services are down, drives are nearly full, load is too high, and so on. I don&#8217;t bother with email alerts, but I really like Monit&#8217;s web front-end and service restarting capabilities.</p>
<div id="attachment_1113" class="wp-caption aligncenter" style="width: 302px"><a href="http://1000umbrellas.com/blog/wp-content/uploads/2010/10/monit.png" rel="lightbox[1109]"><img class="size-medium wp-image-1113" title="monit" src="http://1000umbrellas.com/blog/wp-content/uploads/2010/10/monit-292x300.png" alt="" width="292" height="300" /></a><p class="wp-caption-text">Monit system monitoring (yes, my server is redlining!)</p></div>
<h2>Install Monit</h2>
<p>Installing Monit on an Ubuntu server is accomplished in the usual way.</p>
<p>$ sudo apt-get install monit</p>
<h2>Configure Monit</h2>
<p>You have to edit a configuration file to start monit on your server.</p>
<p><code>$ sudo nano /etc/defaults/monit</code></p>
<p>Default configuration file</p>
<pre># Defaults for monit initscript
# sourced by /etc/init.d/monit
# installed at /etc/default/monit by maintainer scripts
# Stefan Alfredsson

# You must set this variable to for monit to start
startup=0

# To change the intervals which monit should run,
# edit the configuration file /etc/monit/monitrc
# It can no longer be configured here.</pre>
<p>You have to change &#8220;startup=0&#8243; to &#8220;startup=1&#8243;.</p>
<h2>Edit the Control File</h2>
<p>Monit&#8217;s control file is the place to set up system, service, and file monitoring. The default control file is all commented out. When I set mine up, I uncommented various lines and inserted sections for each service at the bottom of the file.</p>
<p><code>$ sudo nano /etc/monit/monitrc</code></p>
<p>Edit the file (uncomment lines), to enable the following options, which set up a monitoring daemon and enables the web interface (http://localhost:2812).</p>
<pre>set daemon  120

set logfile syslog facility log_daemon

set httpd port 2812
allow localhost
allow 192.168.1.0/255.255.255.0

check system localhost

if loadavg (1min) &gt; 4 then alert
if loadavg (5min) &gt; 2 then alert
if memory usage &gt; 75% then alert
if cpu usage (user) &gt; 70% then alert
if cpu usage (system) &gt; 30% then alert
if cpu usage (wait) &gt; 20% then alert

check filesystem root with path /</blockquote>

Add the following sections to the bottom of the file to monitor cron, <a href="http://1000umbrellas.com/2010/09/25/how-to-install-openssh-on-ubuntu-server">sshd</a>, <a href="http://1000umbrellas.com/2010/10/01/how-to-set-up-samba-on-ubuntu-server">samba</a>, <a href="http://1000umbrellas.com/2010/10/03/how-to-install-and-configure-mediatomb-upnp-server-on-ubuntu-server">mediatomb</a>, lighttpd, and MySQL (which I am running to sync XMBC across multiple PCs). Services that run with a pid file are simple to monitor. MySQL does not run with a pidfile, but can easily be configured to by adding the line <code>"pid-file = /var/run/mysqld/mysqld.pid</code>" to the [mysqlid] section of <code>/etc/mysql/my.cnf</code>.
<blockquote>
# cron
check process cron with pidfile /var/run/crond.pid
group system
start program = "/etc/init.d/cron start"
stop  program = "/etc/init.d/cron stop"
if 5 restarts within 5 cycles then timeout
depends on cron_rc

check file cron_rc with path /etc/init.d/cron
group system
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor

# sshd
check process sshd with pidfile /var/run/sshd.pid
start program  "/etc/init.d/ssh start"
stop program  "/etc/init.d/ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

#  samba
check process smbd with pidfile /var/run/samba/smbd.pid
group samba
start program = "/etc/init.d/smbd start"
stop  program = "/etc/init.d/smbd stop"
if failed host 192.168.1.3 port 139 type TCP  then restart
if 5 restarts within 5 cycles then timeout

# mediatomb
check process mediatomb with pidfile /var/run/mediatomb.pid
group mediatomb
start program = "/etc/init.d/mediatomb start"
stop  program = "/etc/init.d/mediatomb stop"
if 5 restarts within 5 cycles then timeout

# lighttpd
check process lighttpd with pidfile /var/run/lighttpd.pid
group lighttpd
start program = "/etc/init.d/lighttpd start"
stop program = "/etc/init.d/lighttpd stop"
if failed host 127.0.0.1 port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout

# mysql
# note: requires mysql to run with a pid.
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout</pre>
<p>Unfortunately, monit can&#8217;t monitor the <a href="http://1000umbrellas.com/2010/10/04/updated-transmission-installationconfiguration-on-ubuntu-server">transmission-daemon</a> service, because transmission-daemon does not run with a pid file, and forks itself sometimes. There is a warning in the transmission-daemon launch script, <code>/etc/init.d/transmission-daemon</code>, which says that pid file support will not work, because the daemon forks. Hopefully this will be resolved in the future.</p>
<h2>Using Monit</h2>
<p>After editing your configuration file, restart monit.</p>
<p><code>$ sudo service monit restart</code></p>
<p>Now you can check the health of your server by pointing a web browser to your server&#8217;s IP address, port 2812 (http://server:2812/).</p>
]]></content:encoded>
			<wfw:commentRss>http://1000umbrellas.com/2010/10/27/how-to-monitor-services-on-ubuntu-lucid-lynx-using-monit/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Updated: How to Automatically Move and Remove Transmission-Daemon Downloads</title>
		<link>http://1000umbrellas.com/2010/10/05/updated-how-to-automatically-move-and-remove-transmission-daemon-downloads</link>
		<comments>http://1000umbrellas.com/2010/10/05/updated-how-to-automatically-move-and-remove-transmission-daemon-downloads#comments</comments>
		<pubDate>Tue, 05 Oct 2010 16:00:25 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[lucid lynx]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Transmission]]></category>
		<category><![CDATA[transmission-daemon]]></category>
		<category><![CDATA[transmission-remote]]></category>

		<guid isPermaLink="false">http://1000umbrellas.com/?p=1069</guid>
		<description><![CDATA[Using the configuration file shown in my Transmission-Daemon setup post, Transmission will download files into the “downloading” folder until the download hits 100%. At that point, the downloaded files will be moved to the “seeding” folder. The torrent will remain active, seeding to other users, until it hits the seeding ratio, or until you pause [...]]]></description>
			<content:encoded><![CDATA[<p>Using the configuration file shown in <a href="http://1000umbrellas.com/2010/10/04/updated-transmission-installationconfiguration-on-ubuntu-server">my Transmission-Daemon setup post</a>, Transmission will download files into the “downloading” folder until the download hits 100%. At that point, the downloaded files will be moved to the “seeding” folder. The torrent will remain active, seeding to other users, until it hits the seeding ratio, or until you pause or remove the torrent. </p>
<p>Left alone, these completed torrents will not be removed from the server, and will accumulate as you download more torrents over time. There is no automated way to remove these torrents. Also, there is no automated way to move files to a new folder after seeding is complete, only after downloading is complete.</p>
<p>My ultimate goals are to complete seeding up until my seeding ratio is hit, to move torrents out of the seeding folder once seeding is complete, and to use the TVNamer Python script to automatically move any TV episodes I have downloaded to my media server&#8217;s TV folder.</p>
<p>Because I want to use <a href="http://1000umbrellas.com/2010/04/27/tvnamer-installationconfiguration">TVNamer</a> to move and rename most of my downloads automatically, but I want them to be seeded up to the ratio I set, I cannot use TVNamer on my “seeding” folder. If I did so, there’s a big chance that files would be removed from my “seeding” folder before seeding was complete. To solve that, I decided to move all completed torrent downloads to another folder, “complete”, and set TVNamer to run on that folder. To move completed torrents, I created a Transmission queue management script, which performs the following actions every 15 minutes:</p>
<ol>
<li>Check for completed downloads that have either been paused manually or have seeded until the seeding ratio.</li>
<li>Move the downloaded files to another folder (“complete”).</li>
<li>Remove the torrent from the Transmission server.</li>
</ol>
<h2>Removing Completed Torrents Using a Script</h2>
<p>Here is the script, which is based on <a href="http://1000umbrellas.com/2010/04/28/how-to-automatically-move-and-remove-transmission-daemon-downloads">my previous version</a>. Compared to my last script, this one’s largest difference is the elimination of the netrc argument in the transmission-remote calls. I noticed that I did not need to send credentials to the Transmission daemon, presumably because my user account has all the privileges it needs to run transmission-remote.</p>
<p>A commenter on my previous post of this script informed me that Transmission 2.x uses “Finished” instead of “Stopped” to indicate completed torrents. I incorporated that change into the script, so that it will work with the old or the new verbiage.</p>
<p>Be sure to change the value of the MOVEDIR to the path you wish to move the downloads to. If you set it to “%1”, you can specify the path as a command-line argument.</p>
<p>Script file: <code>/home/mjdescy/bin/removecompletedtorrents</code></p>
<blockquote><p>#!/bin/sh</p>
<p># script to check for complete torrents in transmission folder, then stop and move them</p>
<p># either hard-code the MOVEDIR variable here&#8230;<br />
MOVEDIR=/home/mjdescy/media # the folder to move completed downloads to<br />
# &#8230;or set MOVEDIR using the first command-line argument<br />
# MOVEDIR=%1</p>
<p># use transmission-remote to get torrent list from transmission-remote list<br />
# use sed to delete first / last line of output, and remove leading spaces<br />
# use cut to get first field from each line<br />
TORRENTLIST=`transmission-remote &#8211;list | sed -e &#8217;1d;$d;s/^ *//&#8217; | cut &#8211;only-delimited &#8211;delimiter= &#8221; &#8221; &#8211;fields=1`</p>
<p># for each torrent in the list<br />
for TORRENTID in $TORRENTLIST<br />
do<br />
  echo &#8220;* * * * * Operations on torrent ID $TORRENTID starting. * * * * *&#8221;</p>
<p>  # check if torrent download is completed<br />
  DL_COMPLETED=`transmission-remote &#8211;torrent $TORRENTID &#8211;info | grep &#8220;Percent Done: 100%&#8221;`</p>
<p>  # check torrent&#8217;s current state is &#8220;Stopped&#8221;, &#8220;Finished&#8221;, or &#8220;Idle&#8221;<br />
  STATE_STOPPED=`transmission-remote &#8211;torrent $TORRENTID &#8211;info | grep &#8220;State: Stopped\|Finished\|Idle&#8221;`</p>
<p>  # if the torrent is &#8220;Stopped&#8221;, &#8220;Finished&#8221;, or &#8220;Idle&#8221; after downloading 100%&#8230;<br />
  if [ "$DL_COMPLETED" != "" ] &#038;&#038; [ "$STATE_STOPPED" != "" ]; then<br />
    # move the files and remove the torrent from Transmission<br />
    echo &#8220;Torrent #$TORRENTID is completed.&#8221;<br />
    echo &#8220;Moving downloaded file(s) to $MOVEDIR.&#8221;<br />
    transmission-remote &#8211;torrent $TORRENTID &#8211;move $MOVEDIR<br />
    echo &#8220;Removing torrent from list.&#8221;<br />
    transmission-remote &#8211;torrent $TORRENTID &#8211;remove<br />
  else<br />
    echo &#8220;Torrent #$TORRENTID is not completed. Ignoring.&#8221;<br />
  fi</p>
<p>  echo &#8220;* * * * * Operations on torrent ID $TORRENTID completed. * * * * *&#8221;</p>
<p>done
</p></blockquote>
<p>After creating the script file, be sure to make it executable.</p>
<p><code>$ sudo chmod u+x /home/mjdescy/bin/removecompletedtorrents</code></p>
<h2>Scheduling the Script</h2>
<p>Schedule execution of the script using cron. </p>
<p><code>$ crontab -e</code></p>
<p>I run the script every 10 minutes, with a 1-minute offset from the top of the hour. I redirect output to /dev/null so cron will not send me emails regarding the script’s output.</p>
<blockquote><p>1,11,21,31,41,51 * * * * /home/mjdescy/bin/removecompletedtorrents > /dev/null 2>&#038;1</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://1000umbrellas.com/2010/10/05/updated-how-to-automatically-move-and-remove-transmission-daemon-downloads/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Redirect Output from Command-line Processes</title>
		<link>http://1000umbrellas.com/2010/06/24/how-to-redirect-output-from-command-line-processes</link>
		<comments>http://1000umbrellas.com/2010/06/24/how-to-redirect-output-from-command-line-processes#comments</comments>
		<pubDate>Thu, 24 Jun 2010 20:39:33 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[/dev/null]]></category>
		<category><![CDATA[2>&1]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[emails from cron]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[stdin]]></category>
		<category><![CDATA[stdout]]></category>

		<guid isPermaLink="false">http://1000umbrellas.com/?p=884</guid>
		<description><![CDATA[This is definitely a newb-level topic, but I think it is important to understand how to redirect output from your command-line processes. This becomes important because regularly-schedule processes run via cron will email you whatever the output is. This is completely confusing when you first encounter it, and the complete solution isn&#8217;t exactly obvious.
StdOut
When you [...]]]></description>
			<content:encoded><![CDATA[<p>This is definitely a newb-level topic, but I think it is important to understand how to redirect output from your command-line processes. This becomes important because regularly-schedule processes run via cron will email you whatever the output is. This is completely confusing when you first encounter it, and the complete solution isn&#8217;t exactly obvious.</p>
<h2>StdOut</h2>
<p>When you run a process on the command line, it will probably output right back to the terminal. This is StdOut, or &#8220;standard output.&#8221; In scripts and cron jobs, however, you might want to redirect output to a file instead, so you can review the output later.</p>
<p>You can redirect output to a new file by using the &#8220;&gt;&#8221; operator.</p>
<p><code>$ ls -l &gt; ~/directory_listing.txt</code></p>
<p>You can redirect output and <em>append</em> it to a file by using the &#8220;&gt;&gt;&#8221; operator. This method will create a file if it does not already exist.</p>
<h2>StdErr</h2>
<p>Error messages are output to StdErr, which by default is redirected to StdOut. This is why you see normal messages and error messages in the terminal when you run a command. StdErr does not have to be redirected to StdOut, however, and has to be treated separately from StdOut if you are redirecting StdOut.</p>
<h2>/dev/null and 2&gt;&amp;1</h2>
<p>Redirecting output to /del/null sends it nowhere, which effectively gets rid of it. You often see output redirected to /dev/null, followed by a cryptic construction <code>2&gt;&amp;1</code>. Here is what <a href="http://docstore.mik.ua/orelly/unix/upt/ch08_13.htm" target="_blank">that construction means</a>:</p>
<p>In the command<br />
<code>$ tvnamer --batch &gt; ~/log/tvnamer.log 2&gt;&amp;1</code></p>
<ul>
<li>2 refers to StdErr; and</li>
<li><code>&amp;1</code> refers to the first redirection argument; in this case, /log/tvnamer.log.</li>
</ul>
<p>My example uses a normal file, instead of /dev/null, to show that you can use  <code>2&gt;&amp;1</code> with any old file.</p>
<p>This construction is very useful if you find that your cron jobs are sending you emails, even after you redirected their output to log files. Cron will automatically email the owner of the cron job any output (on StdOut) from them. This is why you sometimes are notified that you have emails when you log into your system. Effective redirection will eliminate these emails.</p>
]]></content:encoded>
			<wfw:commentRss>http://1000umbrellas.com/2010/06/24/how-to-redirect-output-from-command-line-processes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Automatically Move and Remove Transmission-Daemon Downloads</title>
		<link>http://1000umbrellas.com/2010/04/28/how-to-automatically-move-and-remove-transmission-daemon-downloads</link>
		<comments>http://1000umbrellas.com/2010/04/28/how-to-automatically-move-and-remove-transmission-daemon-downloads#comments</comments>
		<pubDate>Thu, 29 Apr 2010 03:00:59 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[automate]]></category>
		<category><![CDATA[bittorrent]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lucid lynx]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[torrent]]></category>
		<category><![CDATA[Transmission]]></category>
		<category><![CDATA[transmission-daemon]]></category>
		<category><![CDATA[transmission-remote]]></category>

		<guid isPermaLink="false">http://1000umbrellas.com/?p=765</guid>
		<description><![CDATA[Transmission-daemon does not automatically remove completed torrents. I created a script to do so, and I run it via a cron job (under my own user ID) on my Ubuntu 10.04 Lucid Lynx Server.
This script uses command line utility transmission-remote (which is installed when you install the transmission-daemon package) to check on the progress of [...]]]></description>
			<content:encoded><![CDATA[<p>Transmission-daemon does not automatically remove completed torrents. I created a script to do so, and I run it via a cron job (under my own user ID) on my Ubuntu 10.04 Lucid Lynx Server.</p>
<p>This script uses command line utility <a href="http://linux.die.net/man/1/transmission-remote" target="_blank">transmission-remote</a> (which is installed when you <a href="http://1000umbrellas.com/2010/04/21/transmission-install-on-ubuntu-10-04-server-lucid" target="_self">install the transmission-daemon package</a>) to check on the progress of all active torrents. Torrents that have completed downloading and seeding will have a status of &#8220;Stopped&#8221; and a (download) percent done of &#8220;100%&#8221;. This script will identify such torrents, move their downloaded files to a different directory, and will remove the torrent from transmission-daemon.</p>
<p>This script depends on using a seeding ratio to stop your torrents from seeding after a certain percentage has been seeded. If your torrents seed indefinitely, transmission-daemon will never stop them, and this script will not know that the torrent is completed.</p>
<p>Note that transmission-daemon has a built-in option to store incomplete downloads in one folder, and move them, when the download completes, to another folder. This script is meant to pick the torrents up afterward, and move them from the download folder to somewhere more permanent. If you just want to remove completed torrents, comment out the line &#8220;<code>transmission-remote --torrent $TORRENTID --netrc $NETRC --move $MOVEDIR</code>&#8220;.</p>
<h2>Script: movecompletedtorrents</h2>
<p>This script is a modified version of the one found at <a href="http://forum.qnap.com/viewtopic.php?f=45&amp;t=25553" target="_blank">http://forum.qnap.com/viewtopic.php?f=45&amp;t=25553</a>.</p>
<pre>#!/bin/sh

# script to check for complete torrents in transmission folder, then stop and move them

MOVEDIR=/home/user/media
NETRC=/home/user/.netrc

# get torrent list from transmission-remote list
# delete first / last line of output
# remove leading spaces
# get first field from each line
TORRENTLIST=`transmission-remote --list --netrc $NETRC | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f1`

# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
  echo "* * * * * Operations on torrent ID $TORRENTID starting. * * * * *"

  # check if torrent was started
  STARTED=`transmission-remote --torrent $TORRENTID --info --netrc $NETRC | grep "Id: $TORRENTID"`
  # echo " - started state = $STARTED" # debug message

  # check if torrent download is completed
  COMPLETED=`transmission-remote --torrent $TORRENTID --info --netrc $NETRC | grep "Percent Done: 100%"`
  # echo " - completed state = $COMPLETED" # debug message

  # check torrent's current state is "Stopped"
  STOPPED=`transmission-remote --torrent $TORRENTID --info --netrc $NETRC | grep "State: Stopped"`
  # echo " - torrent stopped seeding = $STOPPED" # debug message

  # if the torrent is "Stopped" after downloading 100% and seeding, move the files and remove the torrent from Transmission
  if [ "$STARTED" != "" ] &amp;&amp; [ "$COMPLETED" != "" ] &amp;&amp; [ "$STOPPED" != "" ]; then
    echo "Torrent #$TORRENTID is completed."
    echo "Moving downloaded file(s) to $MOVEDIR."
    transmission-remote --torrent $TORRENTID --netrc $NETRC --move $MOVEDIR
    echo "Removing torrent from list."
    transmission-remote --torrent $TORRENTID --netrc $NETRC --remove
  else
    echo "Torrent #$TORRENTID is not completed. Ignoring."
  fi

  echo "* * * * * Operations on torrent ID $TORRENTID completed. * * * * *"

done</pre>
<h2>Scheduling</h2>
<p>To run this script every hour, save the script somewhere (/home/user/bin), grant yourself permission to execute it&#8230;</p>
<p><code>$ chmod u+x ~/bin/movecompletedtorrents</code></p>
<p>&#8230;edit your crontab settings&#8230;</p>
<p><code>$ crontab -e</code></p>
<p>&#8230;and add the following line.</p>
<p><code>@hourly /home/user/bin/movecompletedtorrents</code></p>
]]></content:encoded>
			<wfw:commentRss>http://1000umbrellas.com/2010/04/28/how-to-automatically-move-and-remove-transmission-daemon-downloads/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TVNamer Installation/Configuration</title>
		<link>http://1000umbrellas.com/2010/04/27/tvnamer-installationconfiguration</link>
		<comments>http://1000umbrellas.com/2010/04/27/tvnamer-installationconfiguration#comments</comments>
		<pubDate>Tue, 27 Apr 2010 15:00:19 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[cross-platform]]></category>
		<category><![CDATA[episodes]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lucid lynx]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[rename]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tv]]></category>
		<category><![CDATA[tv series]]></category>

		<guid isPermaLink="false">http://1000umbrellas.com/?p=749</guid>
		<description><![CDATA[TVNamer is a Python application that will automatically renames TV episode files to a clean, consistent, and useful format. If you rip your DVDs, or download torrents (for shame!) on your server, you might find the &#8220;tvnamer&#8221; Python script very useful. I am running this on my Ubuntu 10.04 Lucid Lynx server right now, and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/dbr/tvnamer/" target="_blank">TVNamer</a> is a Python application that will automatically renames TV episode files to a clean, consistent, and useful format. If you rip your DVDs, or download torrents (for shame!) on your server, you might find the &#8220;tvnamer&#8221; Python script very useful. I am running this on my Ubuntu 10.04 Lucid Lynx server right now, and I am very happy with it.</p>
<h2>How It Works</h2>
<p>I thought I would have to write a complex regular expressions script to reformat the junky file names I end up with. TVNamer does this behind the scenes, and goes one very useful step beyond that: it compares the file names you pass it to <a href="http://thetvdb.com/" target="_blank">the TVDB</a> database, via the TVDB API, to ensure you get a good match. The TVDB is an open database that stores the show titles, episode numbers, and so on, for nearly any show you can think of. As long as your file name contains the series title (in some format or another), and the season and episode numbers (S01E01, for example), TVNamer will rename them nicely.</p>
<h2>Installation</h2>
<p>TVNamer requires Python 2.6. If you don&#8217;t have it, install it as follows:</p>
<p><code>apt-get install python2.6</code></p>
<p>The tvnamer program is simple to install on Ubuntu (I run Ubuntu Server 10.04 Lucid Lynx) via Python&#8217;s &#8220;easy_install&#8221; command. (This probably works on all platforms that Python runs on, too.)</p>
<p>$ sudo easy_install tvnamer</p>
<h2>Running Manually</h2>
<p>You can run tvnamer on one file&#8230;</p>
<p><code>$ tvnamer seriesname.s01e01.crap.you.do.not.care.about.in.the.file.name.mkv</code></p>
<p>&#8230;or on an entire folder.</p>
<p><code>$ tvnamer ~/media/tv/</code></p>
<p>It can also recursively run on any folder tree that you pass to it. I have found this to be the default behavior, though, so the &#8211;recursive argument does not appear to be necessary. (I tend to use the argument in my cron jobs, in case future versions of tvnamer start to require it.)</p>
<p><code>$ tvnamer --recursive ~/media/tv/</code></p>
<p>Note that when you run the program as written above, it will run in interactive mode. For each file you pass to it, you will have to verify the series name and verify that you wish to rename the file.</p>
<h2>Running Automatically on a Schedule</h2>
<p>Fortunately, you can also run tvnamer in batch mode. Batch mode will not prompt the user at all, and will automatically select the most-relevant series title and will automatically rename each file. This is the mode to run tvnamer via a cron job or a shell script.</p>
<p>Batch mode:</p>
<p><code>$ tvnamer --batch ~/media/tv/</code></p>
<p>To schedule a cron job to run this script hourly, run:</p>
<p><code>$ crontab -e</code></p>
<p>and then add the following line to your crontab:</p>
<p><code>@hourly tvnamer --batch --recursive ~/media/tv/</code></p>
<p>and finally save the crontab file.</p>
]]></content:encoded>
			<wfw:commentRss>http://1000umbrellas.com/2010/04/27/tvnamer-installationconfiguration/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

