<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>emre şahin's digital garden 🍃 - cron</title>
    <link>https://emresahin.net/tags/cron/</link>
    <description>Posts in the cron tag</description>
    <language>en</language>
    <managingEditor>contact@emresahin.net (Emre Şahin)</managingEditor>
    <lastBuildDate>Tue, 15 Sep 2026 19:46:32 +0000</lastBuildDate>
    <atom:link href="https://emresahin.net/tags/cron/rss.xml" rel="self" type="application/rss+xml"/>
    <item>
      <title>Regular and Recurring Tasks in todo.txt</title>
      <published>2018-02-06T10:23:22+00:00</published>
      <updated>2018-02-06T10:23:22+00:00</updated>
      <author>Emre Şahin</author>
      <pubDate>Tue, 06 Feb 2018 10:23:22 +0000</pubDate>
      <link>https://emresahin.net/recurrent-todo-txt-14085-74577/</link>
      <guid isPermaLink="true">https://emresahin.net/recurrent-todo-txt-14085-74577/</guid>
      <description>I use the todo.txt format to manage some of my daily tasks. It’s a plain-text format, and both iOS and Android have apps, such as SimpleTasks . Emacs and Vim also support the format. Actually, you don’t need a special editor for it; the format is so simple that even Notepad is sufficient. I have ...</description>
      <category>Productivity</category>
      <category>Automation</category>
      <category>todo.txt</category>
      <category>zsh</category>
      <category>productivity</category>
      <category>cron</category>
      <category>linux</category>
      <content:encoded><![CDATA[<p>I use the <a href="http://todotxt.org/">todo.txt format</a> to manage some of my daily tasks. It’s a
plain-text format, and both iOS and Android have apps, such as
<a href="https://play.google.com/store/apps/details?id=nl.mpcjanssen.todotxtholo">SimpleTasks</a>. <a href="https://github.com/avillafiorita/todotxt-mode">Emacs</a> and <a href="https://github.com/freitass/todo.txt-vim">Vim</a> also support
the format. Actually, you don’t need a special editor for it; the format
is so simple that even Notepad is sufficient.</p>
<p>I have a shell script to add daily recurring tasks, such as “Drink Water” or
“Pray Maghreb,” to this file. SimpleTasks expects the file to be at
<code>$HOME/Dropbox/todo/todo.txt</code>, and I use a template file, such as <code>template.txt</code>,
to populate it. However, as anyone who has used TODO files knows, there are
always unfinished tasks; for instance, I don’t always drink my daily allotted
amount of water.</p>
<p>So, my evening script moves completed tasks (marked as DONE) to their own file,
removes recurring tasks from <code>todo.txt</code>, and repopulates them for a new day.
(Note: The code below is not usable as-is; you must define the <code>TODO</code>, <code>DONE</code>,
and <code>TEMPLATE</code> file paths correctly.)</p>
<pre><code class="language-zsh">
TODO=.../todo.txt
DONE=.../$(date +%F)-done.txt
TEMPLATE=.../template.txt

#Move Done to $DONE
grep -wE '^x ' $TODO &gt;&gt; $DONE
sed -i '/^x /d' $TODO

#Delete lines with @Evening, @Morning or @Regular tags from todo
sed -i "/\b\(@Morning|@Evening|@Regular\)\b/d" $TODO
cat $TODO_TEMPLATE &gt;&gt; $TODO
</code></pre>
<p>I have configured <code>cron</code> to run this every day at 6 PM. (My “evening” starts
earlier than my morning.)</p>]]></content:encoded>
    </item>
    <item>
      <title>Backup Script for Recent Files</title>
      <published>2014-02-01T22:00:00+00:00</published>
      <updated>2014-02-01T22:00:00+00:00</updated>
      <author>Emre Şahin</author>
      <pubDate>Sat, 01 Feb 2014 22:00:00 +0000</pubDate>
      <link>https://emresahin.net/backup-script-for-recent-files/</link>
      <guid isPermaLink="true">https://emresahin.net/backup-script-for-recent-files/</guid>
      <description>I decided to write a script to back up only recent files. There are solutions based on unison that work periodically for all files, but as I change projects, I need to configure new backups for these projects as well. This is cumbersome and error-prone; it is easy to forget to add new artifacts t...</description>
      <category>cli</category>
      <category>tools</category>
      <category>devops</category>
      <category>backup</category>
      <category>rsync</category>
      <category>unison</category>
      <category>bash</category>
      <category>script</category>
      <category>cron</category>
      <category>linux</category>
      <category>automation</category>
      <content:encoded><![CDATA[<p>I decided to write a script to back up only recent files. There are solutions based on <a href="http://www.cis.upenn.edu/~bcpierce/unison/">unison</a> that work periodically for all files, but as I change projects, I need to configure new backups for these projects as well. This is cumbersome and error-prone; it is easy to forget to add new artifacts to backup scripts and lose them in an emergency.</p>
<p>Therefore, I decided that a small Bash script using <a href="http://rsync.samba.org/">rsync</a> and <a href="http://en.wikipedia.org/wiki/Find">find</a> would work better. It monitors my entire home directory and backs up recent files.</p>
<p>The following script does exactly that:</p>
<pre><code class="language-bash">#!/bin/bash

if [ "x$1" = "x" ] ; then
    TARGET=/media/augustus/backup-recent-`hostname`
else
    TARGET=$1
fi

PERIOD=15

mkdir -p $TARGET

# Delete files older than $PERIOD days
find $TARGET -ctime +$PERIOD -print -delete

# Copy files newer than $PERIOD under ~. Ignore files under .hg
for d in ~/*/ ; do
    find $d -path '*/.hg/*' -prune -o -type f -ctime -$PERIOD -print  -exec rsync -aRv {} $TARGET/ \;
done
</code></pre>
<p>It checks whether a command-line option is provided as the target; otherwise, it sets a default target. <code>/media/augustus/</code> is an NFS mount in my case, but you can specify any path.</p>
<p><code>PERIOD</code> is the number of days that the script considers <em>recent</em>. Currently, it backs up files changed in the last 15 days.</p>
<p>The script deletes older files from the backup. Since I use other solutions for long-term storage, I don’t want to keep them here, especially since this script runs via <code>cron</code> every two hours.</p>
<p>Note that the script only checks directories under the home directory, so files located directly in the home directory are not backed up.</p>
<p>It also skips files under <code>.hg</code> directories. You can add more <code>-prune</code> options to the <code>find</code> command to exclude other irrelevant directories from your backup.</p>]]></content:encoded>
    </item>
  </channel>
</rss>
