I have tried the following to no avail, the script just stops after the first input.
filename="..."
while IFS="" read -r line; do
echo "$line" | nc <target> <port>
done < "$filename"
I have tried with a FIFO too:
filename=".."
# Create a named pipe if it doesn’t exist
PIPE=/tmp/nc_pipe
[ -p "$PIPE" ] || mkfifo "$PIPE"
# Start Netcat in the background
nc <target> <port> < "$PIPE" | while read -r response; do
echo "Server response: $response"
done &
while IFS= read -r line; do
echo "$line" > "$PIPE"
sleep 0.5
done < "$filename"
# Cleanup
rm -f "$PIPE"
The simple command works:
echo test | nc <target> <port>
Is there an issue with netcat in Bash scripts?
ncproblem at all. What happens if you replaceecho "$line" | nc <target> <port>withecho "$line" | cat?