我在下面有这个脚本 -
#!/bin/bash
INPUT=/cygdrive/c/apps/dcm4che-2.0.25-bin/SUID_TEST
BASEDIR=/cygdrive/c/apps/dcm4che-2.0.25-bin/bin
TWIDDLE=/cygdrive/c/apps/dcm4chee-2.17.2-mssql/bin/twiddle.sh
#Administrator login and password
LOGIN=mylogin
PASSWORD=mypass
count=0
exec 3<&0 # Save stdin to file descriptor 3.
exec 0<$INPUT # Redirect standard input.
while read line
do
input1=$(echo $line | awk '{ print $1}')
echo "Deleting :" ${input1}
$TWIDDLE -u ${LOGIN} -p ${PASSWORD} -s jnp://192.168.50.51:1099 invoke "dcm4chee.archive:service=ContentEditService" purgeStudy ${input1}
count=$( expr $count + 1 )
sleep 30
done
exec 0<&3 # Restore old stdin.
echo "Counter:" $count # Show deleted items
输入文件&#39; SUID_TEST&#39;将有超过100,000行,每行看起来像&#39; 1.2.124.113532.192.168.50.52.20070330.204624.1634650&#39;。
我要做的是让脚本只读50行,睡10分钟,继续读50行,睡10分钟,直到它到达输入文件的末尾。
现在,它只会运行直到它到达文件的末尾。
有人可以帮助我解决这个问题吗?
谢谢
- 只需在此放置一些代码 - 新脚本我正在使用:
#!/bin/bash
INPUT=/cygdrive/c/apps/dcm4che-2.0.25-bin/SUID_TEST
BASEDIR=/cygdrive/c/apps/dcm4che-2.0.25-bin/BIN
TWIDDLE=/cygdrive/c/apps/dcm4chee-2.17.2-mssql/bin/twiddle.sh
LOGIN=mylogin
PASSWORD=mypass
cnt=0
count=0
exec 3<&0 #Save stdin to file descriptor 3.
exec 0<$INPUT #redirect standard input
while read input1 rest # Let read split the line instead of running awk
do
echo "Row $count"
((cnt++))
echo "Deleting :" ${input1}
$TWIDDLE -u ${LOGIN} -p ${PASSWORD} -s jnp://192.168.50.51:1099 invoke "dcm4chee.archive:service=ContentEditService" purgeStudy ${input1}
((count++))
if (( cnt == 50 )); then
echo "Sleeping for 10 minutes on" | date
sleep 600
cnt=0
fi
done
exec 0<$3
echo "Counter:" $cnt #show deleted items
答案 0 :(得分:2)
计算你的循环迭代,睡觉并在计数器达到50时重置计数器。
cnt=0
count=0
while read input1 rest # Let read split the line instead of running awk
do
echo "Row $count"
((cnt++))
echo "Deleting :" ${input1}
$TWIDDLE -u ${LOGIN} -p ${PASSWORD} -s jnp://192.168.50.51:1099 invoke "dcm4chee.archive:service=ContentEditService" purgeStudy ${input1}
((count++))
if (( cnt == 50 )); then
date
sleep 600
cnt=0
fi
done
要删除对exec
语句的需要,只需从不同的文件描述符中读取read
命令(通常为3),然后将输入文件重定向到while循环&#39 ; s文件描述符3.
while read -u3 input1 rest; do
...
done 3< "$INPUT"