0

I am trying to run a cron job for my code to execute for that i have created a bash file, but my bash file is not working, i am getting error as:

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

My bash scirpt is as follow:

#!/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

Also in my move_files.py i have written a code to move files from one location to another and delete files in one directory. Please find my python code below:

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)

i am not getting where am i making mistake. Please help

Ironman
  • 1,330
  • 2
  • 19
  • 40
  • In your bash script you're getting a syntax error but it's not reflected in your code. And if you have another question with your Python code it should be put into another thread. – knh190 Jan 18 '19 at 07:33
  • Did you write the script in windows and are executing it in linux? Try `dos2unix` on all the files involved. – najeem Jan 18 '19 at 07:34

0 Answers0