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?
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
 
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:
Marked one of my answers as best.

Poster seems to have had question answered.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.