0

i trying to make a script to organize a pair of list i have, and process with other programs, but im a little bit stuck now.

I want from a List in Txt process every line first creating a folder to each line in the list and then process due to different scripts i have.

But my problem is is the list i give to the script is like 3-4 elements works great and create there own directory, but if i put a list with +1000 lines, then my script process only a few elements thru the scripts.

EDIT: the process are like 30-35 scripts, different language python,bash,python and golang

Any suggestions?

cat $STORES+NEW.txt | while read NEWSTORES 
do
    cd $STORES && mkdir $NEWSTORES && cd $NEWSTORES && mkdir .Files
    python3 checkstatus.py -n $NEWSTORES
    checkemployes $NEWSTORES -status
    storemanagers -s $NEWSTORES -o $NEWSTORES+managers.txt
    curl -s https://redacted.com/store?=$NEWSTORES | grep -vE "<|^[\*]*[\.]*$NEWSTORES" | sort -u | awk 'NF' > $NEWSTORES+site.txt
     ..
     ..
     ..
     ..
     ..
     ..
    cd ../..
done
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
joop
  • 1
  • 3

1 Answers1

1

I'm not supposed to give an answer yet but I mistakenly answered my what should be a comment reply. Anyway here a few things I can suggest:

  • Avoid unnecessary use of cat.

  • Open your input file using another FD to prevent commands that read input inside the loop from eating the input: IFS= read -ru 3 NEWSTORES; do ...; done 3< "$STORES+NEW.txt" or { IFS= read -ru "$FD" NEWSTORES; do ...; done; } {FD}< "$STORES+NEW.txt". Also see https://stackoverflow.com/a/28837793/445221.

  • Not completely related but don't use while loop in a pipeline since it will execute in a subshell. In the future if you try to alter a variable and expect it to be saved outside the loop, it won't. You can use lastpipe to avoid it but it's unnecessary most of the time.

  • Place your variable expansions around double quotes to prevent unwanted word splitting and filename expansion.

  • Use -r option unless you want backslashes to escape characters.

  • Specify IFS= before read to prevent stripping of leading and trailing spaces.

  • Using readarray or mapfile makes it more convenient: readarray -t ALL_STORES_DATA < "$STORES+NEW.txt"; for NEWSTORES IN "${ALL_STORES_DATA[@]}"; do ...; done

  • Use lowercase characters on your variables when you don't use them in a global manner to avoid conflict with bash's variables.

konsolebox
  • 72,135
  • 12
  • 99
  • 105