<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Linux on H&amp;W</title>
    <link>https://yy-tech.online/categories/linux/</link>
    <description>Recent content in Linux on H&amp;W</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Thu, 28 May 2026 00:53:02 +0800</lastBuildDate>
    <atom:link href="https://yy-tech.online/categories/linux/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Crontab Issue Tracking</title>
      <link>https://yy-tech.online/post/play-with-contab/</link>
      <pubDate>Mon, 07 Aug 2017 12:33:21 +0800</pubDate>
      <guid>https://yy-tech.online/post/play-with-contab/</guid>
      <description>&lt;h2 id=&#34;how-to-track-issue&#34;&gt;how to track issue&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;sudo /var/log/syslog &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep cron
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2 id=&#34;capture-the-output&#34;&gt;capture the output&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;2&lt;/span&gt; * * * /home/hyy/Start.py &amp;gt;/tmp/output.log 2&amp;gt;&lt;span class=&#34;p&#34;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2 id=&#34;check-cron-is-running&#34;&gt;check cron is running&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  ps -ef &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep cron &lt;span class=&#34;p&#34;&gt;|&lt;/span&gt; grep -v grep
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;h2 id=&#34;check-the-path-is-correct&#34;&gt;check the path is correct&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;crontab  is running in with cwd == $HOME, if you using python os.getcwd() in different folder structure, make sure you cd to the correct place or else it will affect your code by output &amp;ldquo;can not find module&amp;rdquo; stuff.&lt;/li&gt;
&lt;li&gt;in short, use absolute path in your command or add &lt;code&gt;source ~/.zshrc&lt;/code&gt; before your crontab script, so it can find the environment variable&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;last-command-in-crontab-should-have-a-blank-line&#34;&gt;last command in crontab should have a blank line&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;this is tricky, if you didn&amp;rsquo;t notice it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;be-careful-the-dot-thing&#34;&gt;be careful the dot thing&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Debian Linux and its derivative (Ubuntu, Mint, etc) have some peculiarities that may prevent your cron jobs from executing; in particular, the files in /etc/cron.d, /etc/cron.{hourly,daily,weekly,monthly} must :
&lt;ul&gt;
&lt;li&gt;be owned by root&lt;/li&gt;
&lt;li&gt;only be writable by root&lt;/li&gt;
&lt;li&gt;not be writable by group or other users&lt;/li&gt;
&lt;li&gt;have a name without any dots &amp;lsquo;.&amp;rsquo; or any other special character but &amp;lsquo;-&amp;rsquo; and &amp;lsquo;_&amp;rsquo; .&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;python issue run in crontab&lt;/li&gt;
&lt;li&gt;make sure python script have #!/usr/bin/python at the beginning, not neccessary&lt;/li&gt;
&lt;li&gt;make sure log the output, so you can debug in a smooth way&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;chmod-to-the-script&#34;&gt;chmod to the script&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;always run in normal user mode, not root user, and do not use
&lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34;&gt;1
&lt;/span&gt;&lt;span class=&#34;lnt&#34;&gt;2
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;c1&#34;&gt;# don&amp;#39;t do this&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  sudo contab -e  
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;if you try to put your log in other file, make sure the perssion of the file is good, some times, guys delete the log file via root user and create a new one with root user, this will cause the permission error.the right way is echo &amp;quot;&amp;quot; &amp;gt; logfile, then you won’t change the original file’s permission and group&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
  </channel>
</rss>
