Создание цикла for вокруг существующего цикла для замены пользовательского ввода

Если у вас есть приложение Mirth, уже прослушивающее порт 10004, тогда у вас не может быть netcat , также прослушивающего тот же порт ( - l Флаг обозначает слушать ). Возможно, вы намеревались писать в порт, а не слушать его:

# Connect once and write many messages
( while :; do echo MSH....; sleep 3; done ) | nc -vvv localhost 10004

или

# Connect for each message
( while :; do echo MSH.... | nc -vvv localhost 10004; sleep 3; done )

Имейте в виду, что существует несколько различных реализаций netcat . Кажется, что каждая реализация обрабатывает разные подмножества флагов ...


Основываясь на новой информации в вашем вопросе, вот еще одно возможное решение:

MESG=
while IFS= read -r LINE || test -n "$MESG"
do
    if test -n "$LINE"
    then
        # Build the message block
        test -z "$MESG" && MESG="$LINE" || MESG=$(printf "%s\n%s" "$MESG" "$LINE")
        continue
    fi

    # Send the message block to the service
    echo "$MESG" | nc -vvv localhost 10004
    MESG=
    sleep 3
done < /path/to/your/messagefile.txt
0
19.05.2019, 23:29
1 ответ

Lo arreglé yo mismo usando otro script y exportando las variables al script principal, así que al final usé estos dos scripts. Guión principal:

#!/bin/bash
echo 'Welk woord zoek je?'
read word
export word

for file in *.srt
do

fileName="$( basename "$file".srt)"
export fileName
./actualScript

done

Guión real:

#!/bin/bash
#Asks For filname and Word

#Searches word and parses the line-numbers 
wordOut=$(grep -i -n -w $word $fileName.srt |cut -f1 -d:)

#Sets all outputs to diffrent line numbers and saves a temp file
for word in $wordOut
do
    echo $word
done >file.tmp

#Parses lines to array, removes temp file
mapfile -t arr <file.tmp
rm file.tmp

#Declares variable for the number of array entries (not used anywhere atm)
ln=${#arr[@]}

#Subtract all array entries with one
one=1
for i in "${arr[@]}"
do
    crc=`expr $i - $one`
    echo $crc
done >two.tmp

#Subtraction result to array2
mapfile -t arr2 <two.tmp
rm two.tmp
echo ${arr2[@]}

#retrieve times
for h in "${arr2[@]}"
do 
    line=$(sed "${h}q;d" $fileName.srt)
    echo $line
done >three.tmp

#replace all commas with decimal points
sed 's/,/./g' three.tmp >four.tmp

#remove temp file 3 and parse 'decimal pointed' to array
rm three.tmp
mapfile -t arr3 <four.tmp
rm four.tmp

echo ${arr3[0]}
echo ${arr3[1]}

# converts HH:MM:SS.sss to fractional seconds
codes2seconds() (
  local hh=${1%%:*}
  local rest=${1#*:}
  local mm=${rest%%:*}
  local ss=${rest#*:}
  printf "%s" $(bc <<< "$hh * 60 * 60 + $mm * 60 + $ss")
)

# converts fractional seconds to HH:MM:SS.sss
seconds2codes() (
  local seconds=$1
  local hh=$(bc <<< "scale=0; $seconds / 3600")
  local remainder=$(bc <<< "$seconds % 3600")
  local mm=$(bc <<< "scale=0; $remainder / 60")
  local ss=$(bc <<< "$remainder % 60")
  printf "%02d:%02d:%06.3f" "$hh" "$mm" "$ss"
)

subtracttimes() (
  local t1sec=$(codes2seconds "$1")
  local t2sec=$(codes2seconds "$2")
  printf "%s" $(bc <<< "$t2sec - $t1sec")
)


for range in "${arr3[@]}"
do  
  mod=$(sed 's/[^0-9]//g' <<< $range)
  duration=$(subtracttimes "${range%% -->*}" "${range##*--> }")
  printf "%s\n" "ffmpeg -i $fileName.mp4 -ss ${range%% -->*} -t $duration -async 1 $word.$mod.$fileName.cut.mp4"


done >final.tmp
sudo chmod 755 final.tmp
./final.tmp
rm final.tmp
0
28.01.2020, 04:30

Теги

Похожие вопросы