1
votes

I have a python program which I need to run at a particular day of a month, so I am using crontab for this task and create a shell script to run this python program.

This is part of my shell script:

#!/bin/bash
filepath='file2018'
cd ${filepath}
python3 file.py

When I run the crontab which executes the shell script, the log file shows the following error:

line 9: python3: command not found 

I'm really confused about why this error occurs because I have already install python3 and I can run python3 directly from the command line.

Besides, if I replace python3 with python, the shell script works! My python version is python2, but I have to use python3 for this program, so I have to use python3 instead of python.

My operating system is Linux CentOS.

Hope someone can give me some tips!

2

2 Answers

3
votes

You can give the full path to the python3 executable. You can get it using the which python3 command. Try it out.

3
votes

in file.py add first line like below and add +x permission to file.py file

#!/usr/bin/python3

it will automatically execute, no need to mention python3 in the script use "which python3" command to know exact path of python3 in your machine