title: root running cron task can't read .txt file generated by www-data user
body: <p>I have a simple php page that writes a file to my server.</p>
  
  <pre><code>// open new file
       $filename = "$name.txt";
      $fh = fopen($filename, "w");
      fwrite($fh, "$name".";"."$abbreviation".";"."$uid".";");
      fclose($fh);
  </code></pre>
  
  <p>I then have a cron job that I know runs as root as test that and need that.</p>
  
  <pre><code>if [[ $EUID -ne 0 ]]; then
     echo "This script must be run as root" 1&gt;&amp;2
     exit 1
  fi
  </code></pre>
  
  <p>The cronjob is a bash script that can detect the file exists, but it can't seem to read the contents of the file.</p>
  
  <pre><code>#!/bin/bash
  
  
  ######################################################
  #### Loop through the files and generate coincode ####
  ######################################################
  for file in /home/test/customcoincode/queue/*
      do
      echo $file
      chmod 777 $file
      echo "read file"
  
      while read -r coinfile; do
        echo $coinfile
      echo "Assign variables from file"
  
  #############################################
  #### Set the variables to from the file #####
  #############################################
  
      coinName=$(echo $coinfile | cut -f1 -d\;)
      coinNameAbreviation=$(echo $coinfile | cut -f2 -d\;)
      UId=$(echo $coinfile | cut -f3 -d\;)
  
      done &lt; $file
  
      echo "`date +%H:%M:%S` - $coinName : Your Kryptocoin is being compiled!"
  
      echo $file
  
      echo "copy $coinName file to generated directory"
  
      cp -b $file /home/test/customcoincode/generatedCoins/$coinName.txt
  
      echo "`date +%H:%M:%S` : Delete queue file"
  
  #   rm -f $file
  
  
  
  done
  </code></pre>
  
  <p><code>echo $file</code> recognises the file exists</p>
  
  <p><code>echo $coinfile</code> is blank</p>
  
  <p>Yet when I <code>nano ./coinfile.txt</code> in terminal I can see clearly there is text in there</p>
  
  <p>I run <code>ls -l</code> and I see that the file has the permissions</p>
  
  <pre><code>-rw-r--r-- 1 www-data www-data
  </code></pre>
  
  <p>I was under the impression that this would still mean the file can be read by other users?
  Do I need to be able to execute the file if i am opening it and reading the contents?</p>
  
  <p>Any advice would be greatly appreciated.  I can expand and show my code if you want, but it was working before when I called a bash script to write the file... and that time it would save the file under root user with rwx for most and then could be read.  But this then caused other issues in the php page, so is not an option.</p>