Skip to content
Advertisement

Crontab python script does not run (with anaconda on linux server)

I have the following list of tasks to complete and they are working successfully.

0 0 */1 * *  bash /home/user/Code/agapov/start_GHR_Y00011285.sh >> ~/cron.log 2>&1
5 0 */1 * *  bash /home/user/Code/agapov/start_GHR_Y00011280.sh >> ~/cron.log 2>&1
10 0 */1 * *  bash /home/user/Code/agapov/start_GHR_Y10001320.sh >> ~/cron.log 2>&1
20 0 */1 * *  bash /home/user/Code/agapov/aggregation.sh >> ~/cron.log 2>&1
25 0 */1 * *  bash /home/user/Code/ivanov/start_API_N00001010.sh >> ~/cron.log 2>&1

The file structure is as follows:

 #!/bin/bash
 source /home/user/anaconda3/bin/activate
 python /home/user/Code/agapov/GHR_Y00011280.py 
 conda deactivate

But then a problem arises, I added several new files for execution and they do not work. Here is an example of the code for such a file

 #!/bin/bash
 source /home/user/anaconda3/bin/activate
 python /home/user/Code/analyzator.py 
 conda deactivate

As you can see, it is completely similar, the python file itself starts and does its job perfectly, but something goes wrong with the crowns

Cron logs:

/home/user/Code/start_analyzator.sh: line 4: conda: command not found
/home/user/Code/start_analyzator.sh: line 2: /home/user/anaconda3/bin/activate
: No such file or directory
/home/user/Code/start_analyzator.sh: line 3: python: command not found
bash: /home/user/Code/ivanov/start_DS_N00001400.sh: No such file or directory
/home/user/Code/start_analyzator.sh: line 4: conda: command not found
/home/user/Code/start_analyzator.sh: line 2: /home/user/anaconda3/bin/activate
: No such file or directory
/home/user/Code/start_analyzator.sh: line 3: python: command not found
/home/user/Code/start_analyzator.sh: line 4: conda: command not found

analyzator – a file that sends a message to a telegram, here are its settings for checking

*/5 * * * * bash /home/user/Code/start_analyzator.sh >> ~/cron.log 2>&1

What could be the problem, some files work fine and others don’t???

Advertisement

Answer

You’re suffering from DOS line-endings inside your shell script, the CR gets interpreted as part of the file name, which indeed does not exist.

One way of dealing with this would be to use a linux editor; another way would be to use

dos2unix < infile > outfile
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement