Solving bash script cronjob Error – No such file or directory

cronjob Error – No such file or directory is an error which occurs because you did not respect rules of using cron.

This post is my attempt to explain to you why this error occurs and how you can solve it, I will also include multiple solutions that could be considered as alternative fixes to the error.

Exploring the Error : cronjob Error – No such file or directory

First of all, the error occurs when you do not respect some basic rules, guidelines or syntax of using cron.

Please make sure the error you have is very similar to this one. You do not want to mix between errors.

                                                                       #
/path/to/script/send.bash: line 2: activate: No such file or directory
                                                                       #

Bellow I make my best attempt at solving the error and present multiple possible solutions.

Solution 1 : using full paths.

The first solution is simple, you should use full paths in your cron code. Just like in the example bellow.

                                                                       #
#!/bin/bash
source /path/to/activate manage_oam_users
python $HOME/path/to/script/sender.py
python $HOME/path/to/script/reciever.py
source /path/to/deactivate
                                                                       #

If you do not know the exact paths to the files, you can use the commands bellow.

                                                                       #
which activate   #or
which deactivate
                                                                       #

Make sure to replace the character ~ with $HOME

This solution should be enough to solve your issue, I have one final extra solution bellow, in case this one did not do the trick.

Solution 2 : search for the activate command.

The second solution is more of a complementary solution to the solution above.

The solution is to search for and find the location of the activate command.

which activate /Users/username/anaconda/bin/activate

Then and add it to the PATH .

And then finally, add this to your bash_profile

                                                                       #
export PATH="/Users/username/anaconda/bin:$PATH"
                                                                       #

I hope the fix above fixed your problem, good luck with the scripts to come.

Summing-up

If you have to go against the recommendations in the Python documentation and want to use relative imports, just know that the first solution solved the error for me and most other developers who had this issue, I hope you found a solution in our article, keep creating and keep coding, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/