Search code examples
pythonbashshellcron

Crontab Source Command


I'm trying add job to cron , ım having this issue :

You must source this script: $ source /home/flask/bin/activate

And when I try to use . in its place ````source```

Then this is the problem :

mesg: ttyname failed: Inappropriate ioctl for device
.: .: is a directory

Here is my crontab file :

SHELL=/bin/bash
PYTHONPATH="/home/flask/"
* * * * * bash -l  /home/flask/bin/activate && python3 application/script/myscript.py

Any help would be great , many thanks.


Solution

  • When you have this in your crontab

    bash -l foo && bar
    

    cron (or, more strictly speaking, the shell invoked by cron) is first going to run bash -l foo and then, as a separate command, bar. This probably not what you want. (It will make any changes to the shell environment done by foo local to that instance of bash, and thus invisible to bar). Also, foo is supposed to be a filename, so . won't work there (hence the ". is a directory" message).

    It might work to do

    bash -c ". /whatever/activate; python3 foo.py"
    

    but I would recommend to put all the stuff required in a single shell script, and invoke that script from cron.

    I'm not sure about the tty stuff. It looks like something really wants a terminal to talk to, but that might be your bash_profile or something similar, since you're running bash with -l.