BASH Script help re-write

My original script:

#!/bin/bash
UTIL=/opt/dcm4che-5.11.0/bin
INPUT=/opt/notes/cs1fill/2017/missing_cs1
suid=/opt/notes/cs1fill/2017/0020000D/suid.txt
cnt=0
START=1
count=$START
END=25000
awk -v S=$START -v E=$END 'NR>=S&&NR<=E {print $1}' $INPUT  | while read input1  #starting at a certain row
do
 echo "Row $count" | tee -a rowcount25k.txt
 ((cnt++))
 echo "Moving :" ${input1}
 $UTIL/findscu -c STORESCP@10.0.0.1:104 -m 00080050=${input1} -r0020000D --out-dir /opt/notes/cs1fill/2017/0020000D --out-file suid.txt
 $UTIL/movescu -c STORESCP@10.0.0.1:104 -m 0020000D=${suid1} --dest cs1FIR
  ((count++))
   if (( cnt == 50 )); then
    echo "Sleeping for 5 Seconds on $(date), I have moved $count exams"
    sleep 5
    cnt=0
   fi
exec 0<$3 #Restore old stdin.
done
echo "Counter:" $((count-START)) # Show moved items



The first command will read from input1 (a list of numbers with one column) and will write to a file named 'suid.txt'.

The 2nd command will read from the file 'suid.txt' to perform the last task.

My problem is that the first command that runs 'findscu' will overwrite the 'suid.txt' instead of adding to it, so I need the 2nd command to finish its task and then go back to the 1st command until it is finished reading from 'input1'.

How can I re-write this to make it do what I expect?

thanks
doc_jayAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
This appears to be a side effect of your findscu program.

You might be able to fix this by...

# Changing this line...
 $UTIL/findscu -c STORESCP@10.0.0.1:104 -m 00080050=${input1} -r0020000D --out-dir /opt/notes/cs1fill/2017/0020000D --out-file suid.txt

# To something like this...
 $UTIL/findscu -c STORESCP@10.0.0.1:104 -m 00080050=${input1} -r0020000D --out-dir /opt/notes/cs1fill/2017/0020000D --out-file - >> suid.txt

Open in new window


Whether or not this will work depends on your findscu code.

In most cases, changing a filename to "-" will emit output on STDOUT, rather than into a file.

The >> suid.txt says to append to the file, rather than overwrite it's contents.
0
doc_jayAuthor Commented:
David,

I tried that out and it didn't append, I guess thats just how the 'findscu' is written maybe.  Is there a way that the script can be written to force the 2nd command to run, which needs to read the 'suid.txt' before its overwritten by reading 'input'?

thanks
0
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Just run the command without a file operation, like this...

 $UTIL/findscu -c STORESCP@10.0.0.1:104 -m 00080050=${input1} -r0020000D --out-dir /opt/notes/cs1fill/2017/0020000D --out-file -

Open in new window


And post what output occurs.

You should see all the output scroll across your terminal.
0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

doc_jayAuthor Commented:
Okay - I gave that a shot.  Seemed to work as it was written.

The 'findscu' command ran just fine and did what what it was supposed to do, it wrote what it found to the out-put directory into a file named '-1'.
0
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
If findscu outputs to STDOUT, then you should be able to use >> suid.txt at the end of your command to append your suid.txt file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Marked one of my answers as best.

Poster seems to have had question answered.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.