title: Shell script not running via crontab on Linux Mint
body: <p>I am just learning Linux, so please bear with me, as might have overlooked something obvious here. I am currently trying to setup a cron job to run a custom shell script. This script is running fine from the terminal but not via cron. Below are the details. I will appreciate any insights from the experienced users.</p>
  <p><strong>System Info</strong></p>
  <pre><code>RELEASE=17.3
  CODENAME=rosa
  EDITION=&quot;Cinnamon 64-bit&quot;
  DESCRIPTION=&quot;Linux Mint 17.3 Rosa&quot;
  DESKTOP=Gnome
  TOOLKIT=GTK
  NEW_FEATURES_URL=http://www.linuxmint.com/rel_rosa_cinnamon_whatsnew.php
  RELEASE_NOTES_URL=http://www.linuxmint.com/rel_rosa_cinnamon.php
  USER_GUIDE_URL=help:linuxmint
  GRUB_TITLE=Linux Mint 17.3 Cinnamon 64-bit
  </code></pre>
  <p><strong>Custom shell script</strong></p>
  <p>Location: <code>/usr/local/bin/make_ls_files.sh</code></p>
  <p>Contents:</p>
  <pre><code>#!/bin/bash
  
  # test script to echo ls stout to files
  # (learning cron jobs)
    
  # tilde path not working in cron, trying full path
  # ls &gt; ~/ls_file_$(date +%F_%H-%M-%S).log
  ls &gt; /home/zion/ls_file_$(date +%F_%H-%M-%S).log
  </code></pre>
  <p>The script runs fine from terminal (from any <code>cwd</code>), it outputs a file <code>/home/zion/ls_file_2016-11-17_17-38-37.log</code> with output of <code>ls</code> in it.</p>
  <p>Now, I have setup a cron job via <code>crontab -e</code>:</p>
  <pre><code># create text files every minute:
  PATH=/usr:/usr/bin:/usr/local/bin
  * * * * * make_ls_files.sh &gt;&gt; /usr/local/bin/make_ls_files_log.log 2&gt;&amp;1
  </code></pre>
  <p>I see in the syslog that it is in fact running, but no output or log entry is created.
  syslog shows this:</p>
  <pre><code>...
  Nov 17 17:42:01 zion-VirtualBox CRON[4845]: (zion) CMD (make_ls_files.sh &gt;&gt; /usr/local/bin/make_ls_files_log.log 2&gt;&amp;1)
  Nov 17 17:42:01 zion-VirtualBox CRON[4844]: (CRON) info (No MTA installed,  discarding output)
  Nov 17 17:43:02 zion-VirtualBox CRON[4850]: (zion) CMD (make_ls_files.sh &gt;&gt; /usr/local/bin/make_ls_files_log.log 2&gt;&amp;1)
  Nov 17 17:43:02 zion-VirtualBox CRON[4849]: (CRON) info (No MTA installed, discarding output)
  </code></pre>
  <p>Any ideas as to why it isn't working and how to debug?</p>
  <h1>EDIT 01:</h1>
  <p>I changed the cron job to:</p>
  <pre><code>* * * * * make_ls_files.sh 2&gt;&gt;$HOME/crontab.log
  </code></pre>
  <p>Now I am getting somewhere, the log file is created in <code>/home/zion/crontab.log</code>, containing:</p>
  <pre><code>/usr/local/bin/make_ls_files.sh: line 6: date: command not found
  /usr/local/bin/make_ls_files.sh: line 6: ls: command not found
  </code></pre>
  <p>Why <code>ls</code> and <code>date</code> are not recognized?</p>
  <h1>EDIT 02</h1>
  <p>Thanks to all, I learned a few things here. As Ruslan pointend out I had 2 issues:</p>
  <ul>
  <li>insufficient permission for log file location</li>
  <li>insufficient path definitions</li>
  </ul>
  <p>Everything is working now, the final cronjob below:</p>
  <pre><code># create text files every minute:
  PATH=/bin:/usr:/usr/bin:/usr/local/bin
  # * * * * * make_ls_files.sh &gt;&gt; /usr/local/bin/make_ls_files_log.log 2&gt;&amp;1
  * * * * * make_ls_files.sh 2 &gt;&gt; $HOME/crontab.log
  </code></pre>