终端命令和Python代码在Bash脚本中不起作用

时间:2019-01-18 07:28:36

标签: python bash cron

我正在尝试为我创建的bash文件执行代码以执行cron作业,但是我的bash文件无法正常工作,出现以下错误:

workflow.sh: line 2: $'\r': command not found
workflow.sh: line 4: $'\r': command not found
script started
': [Errno 2] No such file or directorye_files.py
workflow.sh: line 7: $'\r': command not found
Training Started
workflow.sh: line 17: syntax error: unexpected end of file

我的bash脚本如下:

#!/bin/bash

touch /home/xxx/file.lock

echo "script started"
python /home/xxx/move_files.py

echo "Training Started"
for N in {1..9}; do /home/xxx/openface-master/util/align-dlib.py /home/xxx/openface-master/training_dataset align outerEyesAndNose /home/xxx/openface-master/aligned_data --size 96 & done

/home/xxx/openface-master/batch-represent/main.lua -outDir /home/xxx/openface-master/feature -data /home/xxx/openface-master/aligned_data

/home/xxx/openface-master/demos/classifier_original.py train feature

echo "Model running"
/home/xxx/openface-master/demos/classifier_updated.py

我在move_files.py中也编写了代码,将文件从一个位置移动到另一个位置,并删除一个目录中的文件。 请在下面找到我的python代码:

import os,shutil

training_data_path = "/home/xxx/openface-master/training_dataset" 
dump_data_path = "/home/xxx/Transfered"
del_align = "/home/xxx/openface-master/aligned_data/cache"

new_file = []
for root,dirs,files in os.walk(dump_data_path):
    for dirname in dirs:
        new_file.append(dirname)

old_file = []
for root,dirs,files in os.walk(training_data_path):
    for dirname in dirs:
        old_file.append(dirname)

commn = list(set(old_file).intersection(new_file))
uncommn = list(set(old_file).symmetric_difference(new_file))

for file in commn:
    for root,dirs,files in os.walk( os.path.join(dump_data_path,file)):
            for img in files:
                src = os.path.join(os.path.join(dump_data_path,file),img)
                dst = os.path.join(os.path.join(training_data_path,file),img)
                print("Src: ", src)
                print("Dst: ", dst)
                shutil.copyfile(src,dst)

for file in uncommn:
    train_dir = os.path.join(training_data_path, file)
    if os.path.isdir(train_dir):
        print("Path exists ")
    else:
        os.mkdir(train_dir)
    for root,dirs,files in os.walk( os.path.join(dump_data_path,file)):
        for img in files:
            src = os.path.join(os.path.join(dump_data_path,file),img)
            dst = os.path.join(os.path.join(training_data_path,file),img)
            print("Src: ", src)
            print("Dst: ", dst)
            shutil.copyfile(src,dst)

def del_folders(path):
    for fname in os.listdir(path):
        if os.path.isdir(os.path.join(path,fname)):
            shutil.rmtree(os.path.join(path,fname))
        else:
            os.remove(os.path.join(path,fname))

def del_files(path):
    if os.path.isfile(path):
        os.remove(path)

del_folders(dump_data_path)
del_files(del_align)

我没弄错我在哪里。请帮助

0 个答案:

没有答案