connect via netcat and send messages in bash script [duplicate]

Clash Royale CLAN TAG#URR8PPP up vote
2
down vote
favorite
This question already has an answer here:
Sending a simple TCP message using Netcat
2 answers
When I am writing a bash script like the following:
#!/bin/bash
nc localhost [pseudoport]
echo "test"
it connects to the server but does not send the text "test".
It works with
#!/bin/bash
echo "test" | nc localhost [pseudoport]
The problem here is that the connection exits after something has been received.
How can I send multiple messages, in my case a fixed preamble followed by a variable data?
networking bash scripts netcat
marked as duplicate by dessert, Eric Carvalho, karel, pa4080, user364819 Feb 13 at 19:16
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
2
down vote
favorite
This question already has an answer here:
Sending a simple TCP message using Netcat
2 answers
When I am writing a bash script like the following:
#!/bin/bash
nc localhost [pseudoport]
echo "test"
it connects to the server but does not send the text "test".
It works with
#!/bin/bash
echo "test" | nc localhost [pseudoport]
The problem here is that the connection exits after something has been received.
How can I send multiple messages, in my case a fixed preamble followed by a variable data?
networking bash scripts netcat
marked as duplicate by dessert, Eric Carvalho, karel, pa4080, user364819 Feb 13 at 19:16
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You are running the script in the command line correct?
â Robby1212
Feb 10 at 16:56
yes that is correct
â OcK
Feb 10 at 16:57
1
What do you mean "send continuously"? Do you want to send a fixed preamble followed by variable data from a file or standard input throughnc(or any process consuming its standard input stream for that matter)?
â David Foerster
Feb 10 at 17:20
Yes @DavidFoerster I wanted to send a fixed preamble followed by a variable data. The link I posted describes how you should do it (from a file).
â OcK
Feb 10 at 17:27
@DavidFoerster done.
â OcK
Feb 10 at 18:37
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
This question already has an answer here:
Sending a simple TCP message using Netcat
2 answers
When I am writing a bash script like the following:
#!/bin/bash
nc localhost [pseudoport]
echo "test"
it connects to the server but does not send the text "test".
It works with
#!/bin/bash
echo "test" | nc localhost [pseudoport]
The problem here is that the connection exits after something has been received.
How can I send multiple messages, in my case a fixed preamble followed by a variable data?
networking bash scripts netcat
This question already has an answer here:
Sending a simple TCP message using Netcat
2 answers
When I am writing a bash script like the following:
#!/bin/bash
nc localhost [pseudoport]
echo "test"
it connects to the server but does not send the text "test".
It works with
#!/bin/bash
echo "test" | nc localhost [pseudoport]
The problem here is that the connection exits after something has been received.
How can I send multiple messages, in my case a fixed preamble followed by a variable data?
This question already has an answer here:
Sending a simple TCP message using Netcat
2 answers
networking bash scripts netcat
networking bash scripts netcat
edited Feb 10 at 18:35
asked Feb 10 at 16:52
OcK
659
659
marked as duplicate by dessert, Eric Carvalho, karel, pa4080, user364819 Feb 13 at 19:16
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by dessert, Eric Carvalho, karel, pa4080, user364819 Feb 13 at 19:16
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You are running the script in the command line correct?
â Robby1212
Feb 10 at 16:56
yes that is correct
â OcK
Feb 10 at 16:57
1
What do you mean "send continuously"? Do you want to send a fixed preamble followed by variable data from a file or standard input throughnc(or any process consuming its standard input stream for that matter)?
â David Foerster
Feb 10 at 17:20
Yes @DavidFoerster I wanted to send a fixed preamble followed by a variable data. The link I posted describes how you should do it (from a file).
â OcK
Feb 10 at 17:27
@DavidFoerster done.
â OcK
Feb 10 at 18:37
add a comment |Â
You are running the script in the command line correct?
â Robby1212
Feb 10 at 16:56
yes that is correct
â OcK
Feb 10 at 16:57
1
What do you mean "send continuously"? Do you want to send a fixed preamble followed by variable data from a file or standard input throughnc(or any process consuming its standard input stream for that matter)?
â David Foerster
Feb 10 at 17:20
Yes @DavidFoerster I wanted to send a fixed preamble followed by a variable data. The link I posted describes how you should do it (from a file).
â OcK
Feb 10 at 17:27
@DavidFoerster done.
â OcK
Feb 10 at 18:37
You are running the script in the command line correct?
â Robby1212
Feb 10 at 16:56
You are running the script in the command line correct?
â Robby1212
Feb 10 at 16:56
yes that is correct
â OcK
Feb 10 at 16:57
yes that is correct
â OcK
Feb 10 at 16:57
1
1
What do you mean "send continuously"? Do you want to send a fixed preamble followed by variable data from a file or standard input through
nc (or any process consuming its standard input stream for that matter)?â David Foerster
Feb 10 at 17:20
What do you mean "send continuously"? Do you want to send a fixed preamble followed by variable data from a file or standard input through
nc (or any process consuming its standard input stream for that matter)?â David Foerster
Feb 10 at 17:20
Yes @DavidFoerster I wanted to send a fixed preamble followed by a variable data. The link I posted describes how you should do it (from a file).
â OcK
Feb 10 at 17:27
Yes @DavidFoerster I wanted to send a fixed preamble followed by a variable data. The link I posted describes how you should do it (from a file).
â OcK
Feb 10 at 17:27
@DavidFoerster done.
â OcK
Feb 10 at 18:37
@DavidFoerster done.
â OcK
Feb 10 at 18:37
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
I have found a way to do this here: Send Commands to socket using netcat
You have to put the messages you want to send in a textfile (lets say msg.txt) and then
nc localhost [pseudoport] < msg.txt
The text file should look like this:
message1
message2
message3
...
Every message has to be in a new line.
The link I posted has a better explanation why this has to be done the way it is done here (there is no explanation in the duplicate article).
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
I have found a way to do this here: Send Commands to socket using netcat
You have to put the messages you want to send in a textfile (lets say msg.txt) and then
nc localhost [pseudoport] < msg.txt
The text file should look like this:
message1
message2
message3
...
Every message has to be in a new line.
The link I posted has a better explanation why this has to be done the way it is done here (there is no explanation in the duplicate article).
add a comment |Â
up vote
2
down vote
accepted
I have found a way to do this here: Send Commands to socket using netcat
You have to put the messages you want to send in a textfile (lets say msg.txt) and then
nc localhost [pseudoport] < msg.txt
The text file should look like this:
message1
message2
message3
...
Every message has to be in a new line.
The link I posted has a better explanation why this has to be done the way it is done here (there is no explanation in the duplicate article).
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
I have found a way to do this here: Send Commands to socket using netcat
You have to put the messages you want to send in a textfile (lets say msg.txt) and then
nc localhost [pseudoport] < msg.txt
The text file should look like this:
message1
message2
message3
...
Every message has to be in a new line.
The link I posted has a better explanation why this has to be done the way it is done here (there is no explanation in the duplicate article).
I have found a way to do this here: Send Commands to socket using netcat
You have to put the messages you want to send in a textfile (lets say msg.txt) and then
nc localhost [pseudoport] < msg.txt
The text file should look like this:
message1
message2
message3
...
Every message has to be in a new line.
The link I posted has a better explanation why this has to be done the way it is done here (there is no explanation in the duplicate article).
edited Feb 10 at 17:33
dessert
20k55795
20k55795
answered Feb 10 at 17:26
OcK
659
659
add a comment |Â
add a comment |Â
You are running the script in the command line correct?
â Robby1212
Feb 10 at 16:56
yes that is correct
â OcK
Feb 10 at 16:57
1
What do you mean "send continuously"? Do you want to send a fixed preamble followed by variable data from a file or standard input through
nc(or any process consuming its standard input stream for that matter)?â David Foerster
Feb 10 at 17:20
Yes @DavidFoerster I wanted to send a fixed preamble followed by a variable data. The link I posted describes how you should do it (from a file).
â OcK
Feb 10 at 17:27
@DavidFoerster done.
â OcK
Feb 10 at 18:37