BASH脚本运行两个命令

时间:2017-12-12 19:00:32

标签: linux bash

我正在尝试调整脚本以运行额外的命令。

我的原始剧本:

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

第一个命令将从input1(一列数字列表)中读取,并将写入名为'suid.txt'的文件。

第二个命令将从文件'suid.txt'读取以执行最后一个任务。

我的问题是运行'findscu'的第一个命令会覆盖'suid.txt'而不是添加它,所以我需要第二个命令来完成它的任务,然后回到第一个命令,直到它是读完'input1'。

任何有待提供的帮助

1 个答案:

答案 0 :(得分:0)

这是关于findscu。此程序具有默认覆盖文件,而不是添加到文件末尾。这对于可能将输出重定向到文件的所有程序来说都是正常的。

例如,tee有特殊参数,不覆盖:

-a      Append the output to the files rather than overwriting them.

我不知道这个程序,但是如果你不给--out-directory和--out-file参数,那么输出是stdout?试试这个:

$UTIL/findscu -c STORESCP@10.0.0.1:104 -m 00080050=${input1} >> /opt/notes/cs1fill/2017/0020000D/suid.txt