<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>crontab &amp;mdash; Paul Sutton</title>
    <link>https://personaljournal.ca/paulsutton/tag:crontab</link>
    <description>Personal Blog</description>
    <pubDate>Tue, 05 May 2026 16:34:51 +0000</pubDate>
    <item>
      <title>Bash scripting 21 - cron</title>
      <link>https://personaljournal.ca/paulsutton/bash-scripting-21-cron</link>
      <description>&lt;![CDATA[Bash scripting 21 - cron&#xA;&#xA;One of the important things you need to do as a system admin is run tasks that perform specific tasks on the system.   This is fine when you are sitting in front of the computer, or logged in remotely, but what happens if you need to run a task when you are not there, or you just want to automate the running of these tasks. &#xA;&#xA;You can schedule tasks using the cron command.   There is an easy-to-use tutorial for this at [1].  I am not going to reproduce this here,  but may include some of my own specific use cases in a later post. &#xA;&#xA;Using cron to schedule tasks&#xA;&#xA;According to [1] the following &#xA;&#xA;/5      /home/paul/crontest.sh&#xA;runs every 5 minutes, where as&#xA;/10      /home/paul/crontest.sh&#xA;So putting ls -l in crontest.sh will run that command every 5 or 10 minutes.&#xA;&#xA;However, I am logged into my pi (where I am running this) so the script will run, but I don&#39;t see any output.&#xA;&#xA;If I add in ls -l   dirlist.txt&#xA;&#xA;It will produce a directory listing text file when run, by running ls manually you can see it in the listing.&#xA;&#xA;I have a post on Ansiweather scheduled fora few days,  in the meantime&#xA;&#xA;putting this in the crontest.sh file&#xA;&#xA;echo $(date), $(ansiweather -l Paignton -a false)     weather.csv&#xA;&#xA;It will run at the specified time and append the information to weather.csv which could be a good way to monitor weather over time.&#xA;&#xA;This can be examined with&#xA;&#xA;cat weather.csv &#xA;if you use the watch command&#xA;&#xA;watch cat weather.csv&#xA;the contents of weather.csv will be displayed and updated in real time as the file is appended with new information.&#xA;&#xA;References&#xA;&#xA;https://stackoverflow.com/questions/12786410/run-cron-job-every-n-minutes-plus-offset&#xA;&#xA;Tags&#xA;&#xA;#Bash,#Bashscripting,#Task,#Schedule,#cron,#crontab,#Admin,&#xA;Automation&#xA;&#xA;hr&#xD;&#xA;&#xD;&#xA;table&#xD;&#xA;thead&#xD;&#xA;trtda rel=&#34;me&#34; href=&#34;https://qoto.org/@zleap&#34;Mastodon/a/td&#xD;&#xA;tda href=&#34;https://wiki.ircnow.org/?n=Shelllabs.Intro&#34;ShellLabs/td&#xD;&#xA;tda href=&#34;https://joinmastodon.org/&#34;Join Mastodon/a/td/tr/thead/table&#xD;&#xA;center&#xD;&#xA;AI statement : b Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity.  Consent CANNOT be assumed, it has to be granted. /b&#xD;&#xA;/center&#xD;&#xA;&#xD;&#xA;a href=&#34;https://liberapay.com/PaulSutton/donate&#34;img alt=&#34;Donate using Liberapay&#34; src=&#34;https://liberapay.com/assets/widgets/donate.svg&#34;/a&#xD;&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Bash scripting 21 – cron</p>

<p>One of the important things you need to do as a system admin is run tasks that perform specific tasks on the system.   This is fine when you are sitting in front of the computer, or logged in remotely, but what happens if you need to run a task when you are not there, or you just want to automate the running of these tasks.</p>

<p>You can schedule tasks using the cron command.   There is an easy-to-use tutorial for this at [1].  I am <strong>not</strong> going to reproduce this here,  but may include some of my own specific use cases in a later post.</p>
<ul><li><a href="https://hostthrive.com/advanced-hosting-techniques/a-beginners-guide-to-using-cron-jobs-for-scheduled-tasks/" rel="nofollow">Using cron to schedule tasks</a></li></ul>

<p>According to [1] the following</p>

<pre><code>*/5  * * * * /home/paul/crontest.sh
</code></pre>

<p>runs every 5 minutes, where as</p>

<pre><code>*/10  * * * * /home/paul/crontest.sh
</code></pre>

<p>So putting ls -l in crontest.sh will run that command every 5 or 10 minutes.</p>

<p>However, I am logged into my pi (where I am running this) so the script will run, but I don&#39;t see any output.</p>

<p>If I add in ls -l &gt; dirlist.txt</p>

<p>It will produce a directory listing text file when run, by running ls manually you can see it in the listing.</p>

<p>I have a post on Ansiweather scheduled fora few days,  in the meantime</p>

<p>putting this in the crontest.sh file</p>

<pre><code>echo $(date), $(ansiweather -l Paignton -a false) &gt;&gt; weather.csv
</code></pre>

<p>It will run at the specified time and append the information to weather.csv which could be a good way to monitor weather over time.</p>

<p>This can be examined with</p>

<pre><code>cat weather.csv 
</code></pre>

<p>if you use the watch command</p>

<pre><code>watch cat weather.csv
</code></pre>

<p>the contents of weather.csv will be displayed and updated in real time as the file is appended with new information.</p>

<p><strong>References</strong></p>
<ol><li><a href="https://stackoverflow.com/questions/12786410/run-cron-job-every-n-minutes-plus-offset" rel="nofollow">https://stackoverflow.com/questions/12786410/run-cron-job-every-n-minutes-plus-offset</a></li></ol>

<p><strong>Tags</strong></p>

<p><a href="/paulsutton/tag:Bash" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Bash</span></a>,<a href="/paulsutton/tag:Bashscripting" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Bashscripting</span></a>,<a href="/paulsutton/tag:Task" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Task</span></a>,<a href="/paulsutton/tag:Schedule" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Schedule</span></a>,<a href="/paulsutton/tag:cron" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">cron</span></a>,<a href="/paulsutton/tag:crontab" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">crontab</span></a>,<a href="/paulsutton/tag:Admin" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Admin</span></a>,
<a href="/paulsutton/tag:Automation" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Automation</span></a></p>

<hr>

<p><table>
<thead>
<tr><td><a href="https://qoto.org/@zleap" rel="nofollow">Mastodon</a></td>
<td><a href="https://wiki.ircnow.org/?n=Shelllabs.Intro" rel="nofollow">ShellLabs</td>
<td><a href="https://joinmastodon.org/" rel="nofollow">Join Mastodon</a></td></tr></thead></table>

AI statement : <b> Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity.  Consent CANNOT be assumed, it has to be granted. </b>
</p>

<p><a href="https://liberapay.com/PaulSutton/donate" rel="nofollow"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a></p>
]]></content:encoded>
      <guid>https://personaljournal.ca/paulsutton/bash-scripting-21-cron</guid>
      <pubDate>Sat, 26 Apr 2025 06:00:00 +0000</pubDate>
    </item>
  </channel>
</rss>