The downside of that can be that cat or the while loop and nc keep running until you hit ^C or ^D on the shell. I chose a small wait time of 10 milliseconds here, so it reacts faster on connection end. Using # works for a bash like remote that would ignore this as a comment. This sends unlimited # characters on the 2nd line of the input. Īlternatively do this: (echo command while true do sleep 0.01 echo -n "#" done) | nc host port The first argument is just getting the echo command through cat – it could also be a file with your commands a la cat < file - |. (If you pipe a very large file you will see that it might get a response before it's done sending the file).Įnter cat with - as second argument: It makes cat listen on stdin for more content to pipe through after it has sent the contents of the first argument. The problem is that nc will close the connection immediately after stdin is closed, which is very quick for a simple my_command string, and thus never gets the chance to receive a response. Use this: cat <(echo command) - | nc host port
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |