user3100345
user3100345

Reputation: 41

Alternative to Cat out of a bash script?

i have an issue with the following.

exec 3<>/dev/tcp/$1/37491

echo -ne 060e2b3 00$hexdec$cmdhex | perl -pe 's/([0-9a-f]{2})/chr hex $1/gie' >&3

cat <&3

i have a server in which i send a hex string to with the port / tcp connection made. BUT since i am using putty through a terminal my first issue is that the XML response back always says PuTTY and it doesnt escape. I also need to put the replies back sometimes in an array and i have tried

array=`cat <&3`

echo "Array items:"
for item in ${array[*]}
do
    printf "   %s\n" $item
done

and i believe since the cat is not exiting properly it just stays open the array is not done?

thanks for the advanced help

Upvotes: 2

Views: 2049

Answers (2)

glenn jackman
glenn jackman

Reputation: 246774

Do you need specify a timeout?

while read -t 5 line <&3; do 
    echo "$line"
    (( Lines++ ))
done
exec 3>&-

Upvotes: 2

Emo Mosley
Emo Mosley

Reputation: 535

Perhaps you need to close the TCP/IP socket?

exec 3>&-

Upvotes: 0

Related Questions