Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

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???

question from:https://stackoverflow.com/questions/65904501/crontab-python-script-does-not-run-with-anaconda-on-linux-server

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...