title: Run python script from shell script using crontab
body: <p>I have a shell script <code>main.sh</code> which runs a python script <code>main.py</code>. When i run the <code>main.sh</code> script manually then the execution is fine (<strong>Note</strong>: <em>i am running it manually with root user</em>) and the python script works as expected. However when i try the same from <strong>crontab</strong> which runs the main.sh script every 30 mins then python script is not getting executed.(i have already done <em>chmod u+x main.sh</em> to make it executable)</p>
  <p>The crontab given below is also of the root user</p>
  <p>my crontab file:
  <code>*/30 * * * * /home/opc/python_scripts/main.sh &gt;&gt; /home/opc/cron.log</code>.</p>
  <p>my main.sh file:</p>
  <pre><code>#!/bin/bash
  output=$(sh /home/opc/python_scripts/url.sh)
  echo &quot;$output&quot;
  searchstring=&quot;url is up, login service is up and oc console is up&quot;
  if [[ &quot;$output&quot; == *&quot;$searchstring&quot;* ]] ; then
      echo &quot;URL is up&quot;
      sudo python3 /home/opc/python_scripts/main.py &gt;&gt; /home/opc/pyfile.log
  else
      echo &quot;URL is Down&quot;
      sudo python3 /home/opc/python_scripts/disable_crr.py
  fi
  </code></pre>
  <p>I know that it is entering the first if condition and it is also printing the &quot;URL is up&quot; statement, i have another log file which records this. When i run it manually then i can see that even python script is running properly but with crontab it gets stuck at <code>echo &quot;URL is up&quot;</code> , after that no execution happens</p>
  <p>Things i have done to solve this:</p>
  <ol>
  <li><p>i have seen solutions of similar questions like-<a href="https://stackoverflow.com/questions/46728815/calling-a-python-script-from-shell-script-cron">Calling a python script from shell script cron</a> , <a href="https://stackoverflow.com/questions/4377109/shell-script-execute-a-python-program-from-within-a-shell-script">Shell Script: Execute a python program from within a shell script</a>, but in all of these questions the user was not able to run the python script from the shell script manually. I am able to run it manually but if i use a <strong>cronjob</strong> then i am having a problem.</p>
  </li>
  <li><p>when i ran ls -la in the directory where these scripts are located the ownership of these files was like:</p>
  </li>
  </ol>
  <pre><code>main.sh root root  
  main.py opc opc
  </code></pre>
  <p>Also i added <code>#!/usr/bin/env python3</code> at the top of my python script as i had seen this as a solution in a similiar question but did not work, only manually works, not with crontab.</p>
  <p>How do i run it with crontab?</p>