How to send literal string over TCP (netcat/socat-like), but provided by command arguments?socat reliable file transfer over TCPLinux Shell Script - Send command over TCP to Sharp AquosCommand line streaming string manipulation from netcatHow to record an interactice socat TCP/TLS session?Expose awk over tcp (inetd, socat, etc.)Using socat to Tunnel/Proxy TCP want to split send/receive into separate filesCreate UDP to TCP bridge with socat/netcat to relay control commands for vlc media-playerWhich layer(IP/TCP?) is netcat/socat working on?Can I resume a failed (ZoL) ZFS send over netcat?socat - UNIX-LISTEN and TCP-LISTEN in one command
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
Escape a backup date in a file name
System.debug(JSON.Serialize(o)) Not longer shows full string
Two monoidal structures and copowering
Why not increase contact surface when reentering the atmosphere?
Unreliable Magic - Is it worth it?
Is a stroke of luck acceptable after a series of unfavorable events?
Is the destination of a commercial flight important for the pilot?
How can I kill an app using Terminal?
Tiptoe or tiphoof? Adjusting words to better fit fantasy races
Is HostGator storing my password in plaintext?
Would a high gravity rocky planet be guaranteed to have an atmosphere?
How to run a prison with the smallest amount of guards?
Large drywall patch supports
What is the difference between "behavior" and "behaviour"?
How to Reset Passwords on Multiple Websites Easily?
Pole-zeros of a real-valued causal FIR system
How to write papers efficiently when English isn't my first language?
Anatomically Correct Strange Women In Ponds Distributing Swords
Integer addition + constant, is it a group?
How does it work when somebody invests in my business?
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
How does Loki do this?
India just shot down a satellite from the ground. At what altitude range is the resulting debris field?
How to send literal string over TCP (netcat/socat-like), but provided by command arguments?
socat reliable file transfer over TCPLinux Shell Script - Send command over TCP to Sharp AquosCommand line streaming string manipulation from netcatHow to record an interactice socat TCP/TLS session?Expose awk over tcp (inetd, socat, etc.)Using socat to Tunnel/Proxy TCP want to split send/receive into separate filesCreate UDP to TCP bridge with socat/netcat to relay control commands for vlc media-playerWhich layer(IP/TCP?) is netcat/socat working on?Can I resume a failed (ZoL) ZFS send over netcat?socat - UNIX-LISTEN and TCP-LISTEN in one command
If I want to send a string over TCP in a shell environment, I can do something like:
echo text | nc 1.2.3.4 9876
Cool. Interactively, that works. Now I want to do this programmatically by spawning a subprocess from another program, so I want to avoid using a shell and pipes.
Also, since I'm deploying with distroless Docker containers, they don't come with a shell.
Is there an existing tool to send an command argument as string over TCP? I'm looking for an (imaginary) variant of nc
, e.g.:
nc 1.2.3.4 9876 text
that does the same as
echo text | nc 1.2.3.4 9876
(Need the output too.)
I'm about to write my own application for this, but I can imagine this exists already, simply taking one of the argv instead of stdin to pass on.
Looked at socat
, which can read from files with OPEN
, which is very close to what I want, but I need the string to be passed as parameter from the command issued.
For the full context, the entrypoint of the Docker container should be settable by it, without shells or other interpreted language, but pure OS native dependencies like glibc (like socat/nc is!).
tcp socket netcat socat
|
show 4 more comments
If I want to send a string over TCP in a shell environment, I can do something like:
echo text | nc 1.2.3.4 9876
Cool. Interactively, that works. Now I want to do this programmatically by spawning a subprocess from another program, so I want to avoid using a shell and pipes.
Also, since I'm deploying with distroless Docker containers, they don't come with a shell.
Is there an existing tool to send an command argument as string over TCP? I'm looking for an (imaginary) variant of nc
, e.g.:
nc 1.2.3.4 9876 text
that does the same as
echo text | nc 1.2.3.4 9876
(Need the output too.)
I'm about to write my own application for this, but I can imagine this exists already, simply taking one of the argv instead of stdin to pass on.
Looked at socat
, which can read from files with OPEN
, which is very close to what I want, but I need the string to be passed as parameter from the command issued.
For the full context, the entrypoint of the Docker container should be settable by it, without shells or other interpreted language, but pure OS native dependencies like glibc (like socat/nc is!).
tcp socket netcat socat
2
If you haven't got a shell, what are you expecting to run your command ?
– X Tian
yesterday
you must have somekind of shell if you can run netcat inside your docker. Don't you have access tobusybox echo
orbusybox cat
commands ?
– Kiwy
yesterday
@XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g.ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
is unnecessary, just doENTRYPOINT ["mycommand"]
. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g.man 2 execve
.
– gertvdijk
yesterday
1
Please read your question you need to use|
to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module tonc
to allow the use of a file as an argument. So if you have a busybox inside you can usebusybox sh
. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.
– Kiwy
yesterday
2
So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.
– Ralph Rönnquist
yesterday
|
show 4 more comments
If I want to send a string over TCP in a shell environment, I can do something like:
echo text | nc 1.2.3.4 9876
Cool. Interactively, that works. Now I want to do this programmatically by spawning a subprocess from another program, so I want to avoid using a shell and pipes.
Also, since I'm deploying with distroless Docker containers, they don't come with a shell.
Is there an existing tool to send an command argument as string over TCP? I'm looking for an (imaginary) variant of nc
, e.g.:
nc 1.2.3.4 9876 text
that does the same as
echo text | nc 1.2.3.4 9876
(Need the output too.)
I'm about to write my own application for this, but I can imagine this exists already, simply taking one of the argv instead of stdin to pass on.
Looked at socat
, which can read from files with OPEN
, which is very close to what I want, but I need the string to be passed as parameter from the command issued.
For the full context, the entrypoint of the Docker container should be settable by it, without shells or other interpreted language, but pure OS native dependencies like glibc (like socat/nc is!).
tcp socket netcat socat
If I want to send a string over TCP in a shell environment, I can do something like:
echo text | nc 1.2.3.4 9876
Cool. Interactively, that works. Now I want to do this programmatically by spawning a subprocess from another program, so I want to avoid using a shell and pipes.
Also, since I'm deploying with distroless Docker containers, they don't come with a shell.
Is there an existing tool to send an command argument as string over TCP? I'm looking for an (imaginary) variant of nc
, e.g.:
nc 1.2.3.4 9876 text
that does the same as
echo text | nc 1.2.3.4 9876
(Need the output too.)
I'm about to write my own application for this, but I can imagine this exists already, simply taking one of the argv instead of stdin to pass on.
Looked at socat
, which can read from files with OPEN
, which is very close to what I want, but I need the string to be passed as parameter from the command issued.
For the full context, the entrypoint of the Docker container should be settable by it, without shells or other interpreted language, but pure OS native dependencies like glibc (like socat/nc is!).
tcp socket netcat socat
tcp socket netcat socat
edited yesterday
gertvdijk
asked yesterday
gertvdijkgertvdijk
7,49252945
7,49252945
2
If you haven't got a shell, what are you expecting to run your command ?
– X Tian
yesterday
you must have somekind of shell if you can run netcat inside your docker. Don't you have access tobusybox echo
orbusybox cat
commands ?
– Kiwy
yesterday
@XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g.ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
is unnecessary, just doENTRYPOINT ["mycommand"]
. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g.man 2 execve
.
– gertvdijk
yesterday
1
Please read your question you need to use|
to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module tonc
to allow the use of a file as an argument. So if you have a busybox inside you can usebusybox sh
. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.
– Kiwy
yesterday
2
So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.
– Ralph Rönnquist
yesterday
|
show 4 more comments
2
If you haven't got a shell, what are you expecting to run your command ?
– X Tian
yesterday
you must have somekind of shell if you can run netcat inside your docker. Don't you have access tobusybox echo
orbusybox cat
commands ?
– Kiwy
yesterday
@XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g.ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
is unnecessary, just doENTRYPOINT ["mycommand"]
. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g.man 2 execve
.
– gertvdijk
yesterday
1
Please read your question you need to use|
to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module tonc
to allow the use of a file as an argument. So if you have a busybox inside you can usebusybox sh
. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.
– Kiwy
yesterday
2
So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.
– Ralph Rönnquist
yesterday
2
2
If you haven't got a shell, what are you expecting to run your command ?
– X Tian
yesterday
If you haven't got a shell, what are you expecting to run your command ?
– X Tian
yesterday
you must have somekind of shell if you can run netcat inside your docker. Don't you have access to
busybox echo
or busybox cat
commands ?– Kiwy
yesterday
you must have somekind of shell if you can run netcat inside your docker. Don't you have access to
busybox echo
or busybox cat
commands ?– Kiwy
yesterday
@XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g.
ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
is unnecessary, just do ENTRYPOINT ["mycommand"]
. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g. man 2 execve
.– gertvdijk
yesterday
@XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g.
ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
is unnecessary, just do ENTRYPOINT ["mycommand"]
. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g. man 2 execve
.– gertvdijk
yesterday
1
1
Please read your question you need to use
|
to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module to nc
to allow the use of a file as an argument. So if you have a busybox inside you can use busybox sh
. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.– Kiwy
yesterday
Please read your question you need to use
|
to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module to nc
to allow the use of a file as an argument. So if you have a busybox inside you can use busybox sh
. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.– Kiwy
yesterday
2
2
So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.
– Ralph Rönnquist
yesterday
So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.
– Ralph Rönnquist
yesterday
|
show 4 more comments
3 Answers
3
active
oldest
votes
I don't know of any program that takes a parameter and sends it over a tcp connection.
However you have sort of answered your own question somewhat within your comments, specifically with the following line.
ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell
and netcat
., then use your original command. Well at least to test whatever you are trying to do.
If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.
One thought, I see this example, shows setup of Python to run a script,
FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app
FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]
which might be easier/quicker than developing a C
program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat
would do what you want, could you use socat
to read from a file (which you include in your image), and that file contains your literal string.
This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.
– gertvdijk
yesterday
I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.
– X Tian
yesterday
add a comment |
I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc
and socat
. Perhaps I might find time to write a patch to nc
to also accept input from an argument.
Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.
Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it asherestring text nc -N host port
. (that will not append a newline totext
, unlikeecho text
).
– mosvy
yesterday
add a comment |
I suppose you could use newlisp
, such as
newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'
and vary parameters as desired.
I'm pretty sure you could use perl
or other interpreters as well, though newlisp
is quite small and it can be compiled into a static program as well.
The above example will make the program connect to localhost
port 3456
, and issue the line go for it
on the socket, then it will exit. Goto the newlisp home site for more details.
JRE ?? Not sure where you got that one from.
– Ralph Rönnquist
yesterday
newlisp.org/index.cgi?Downloads shows a JRE dependency to me?
– gertvdijk
yesterday
It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.
– Ralph Rönnquist
yesterday
Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!
– gertvdijk
yesterday
Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.
– Ralph Rönnquist
yesterday
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508688%2fhow-to-send-literal-string-over-tcp-netcat-socat-like-but-provided-by-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I don't know of any program that takes a parameter and sends it over a tcp connection.
However you have sort of answered your own question somewhat within your comments, specifically with the following line.
ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell
and netcat
., then use your original command. Well at least to test whatever you are trying to do.
If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.
One thought, I see this example, shows setup of Python to run a script,
FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app
FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]
which might be easier/quicker than developing a C
program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat
would do what you want, could you use socat
to read from a file (which you include in your image), and that file contains your literal string.
This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.
– gertvdijk
yesterday
I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.
– X Tian
yesterday
add a comment |
I don't know of any program that takes a parameter and sends it over a tcp connection.
However you have sort of answered your own question somewhat within your comments, specifically with the following line.
ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell
and netcat
., then use your original command. Well at least to test whatever you are trying to do.
If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.
One thought, I see this example, shows setup of Python to run a script,
FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app
FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]
which might be easier/quicker than developing a C
program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat
would do what you want, could you use socat
to read from a file (which you include in your image), and that file contains your literal string.
This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.
– gertvdijk
yesterday
I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.
– X Tian
yesterday
add a comment |
I don't know of any program that takes a parameter and sends it over a tcp connection.
However you have sort of answered your own question somewhat within your comments, specifically with the following line.
ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell
and netcat
., then use your original command. Well at least to test whatever you are trying to do.
If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.
One thought, I see this example, shows setup of Python to run a script,
FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app
FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]
which might be easier/quicker than developing a C
program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat
would do what you want, could you use socat
to read from a file (which you include in your image), and that file contains your literal string.
I don't know of any program that takes a parameter and sends it over a tcp connection.
However you have sort of answered your own question somewhat within your comments, specifically with the following line.
ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
I appreciate that you seem to want the minimalist footprint of applications in your image, but I believe the best solution is to have a shell
and netcat
., then use your original command. Well at least to test whatever you are trying to do.
If at the end of the day, you want to drop back to only one executable, you'll have to write your own program to do it.
One thought, I see this example, shows setup of Python to run a script,
FROM python:2.7-slim AS build-env
ADD . /app
WORKDIR /app
FROM gcr.io/distroless/python2.7
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.py", "/etc"]
which might be easier/quicker than developing a C
program to do it all, but then effectively you are using Python as the SHELL. Lastly, if you think socat
would do what you want, could you use socat
to read from a file (which you include in your image), and that file contains your literal string.
edited yesterday
sourcejedi
25.5k445110
25.5k445110
answered yesterday
X TianX Tian
7,78112237
7,78112237
This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.
– gertvdijk
yesterday
I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.
– X Tian
yesterday
add a comment |
This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.
– gertvdijk
yesterday
I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.
– X Tian
yesterday
This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.
– gertvdijk
yesterday
This is not an answer to my question, sorry. I was asking if there was a program already that implements the 10 lines of C code to write arguments to a socket, instead stdin.
– gertvdijk
yesterday
I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.
– X Tian
yesterday
I started my answer saying I don't think there is such a program, and then went on to suggest alternative solutions. I also think having a couple of utilities (shell, php, busbox) still constitutes a distroless container, minimising the the available targets.
– X Tian
yesterday
add a comment |
I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc
and socat
. Perhaps I might find time to write a patch to nc
to also accept input from an argument.
Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.
Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it asherestring text nc -N host port
. (that will not append a newline totext
, unlikeecho text
).
– mosvy
yesterday
add a comment |
I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc
and socat
. Perhaps I might find time to write a patch to nc
to also accept input from an argument.
Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.
Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it asherestring text nc -N host port
. (that will not append a newline totext
, unlikeecho text
).
– mosvy
yesterday
add a comment |
I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc
and socat
. Perhaps I might find time to write a patch to nc
to also accept input from an argument.
Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.
I've written my own small application to implement what I need. Reads arguments and writes them to a socket. Too bad that it didn't exist yet, but only more complicated features are available in tools like nc
and socat
. Perhaps I might find time to write a patch to nc
to also accept input from an argument.
Re comments - I find it a bit sad to read including a full shell and spawning subprocesses from it is the new norm. Pure overhead we don't need.
edited yesterday
answered yesterday
gertvdijkgertvdijk
7,49252945
7,49252945
Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it asherestring text nc -N host port
. (that will not append a newline totext
, unlikeecho text
).
– mosvy
yesterday
add a comment |
Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it asherestring text nc -N host port
. (that will not append a newline totext
, unlikeecho text
).
– mosvy
yesterday
Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it as
herestring text nc -N host port
. (that will not append a newline to text
, unlike echo text
).– mosvy
yesterday
Instead of writing such a narrow utililty, you could've written a wrapper that "transforms" some command line arguments into a file and then exec's another program with its stdin redirected from it. Simple POC (linux-only) here. You can use it as
herestring text nc -N host port
. (that will not append a newline to text
, unlike echo text
).– mosvy
yesterday
add a comment |
I suppose you could use newlisp
, such as
newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'
and vary parameters as desired.
I'm pretty sure you could use perl
or other interpreters as well, though newlisp
is quite small and it can be compiled into a static program as well.
The above example will make the program connect to localhost
port 3456
, and issue the line go for it
on the socket, then it will exit. Goto the newlisp home site for more details.
JRE ?? Not sure where you got that one from.
– Ralph Rönnquist
yesterday
newlisp.org/index.cgi?Downloads shows a JRE dependency to me?
– gertvdijk
yesterday
It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.
– Ralph Rönnquist
yesterday
Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!
– gertvdijk
yesterday
Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.
– Ralph Rönnquist
yesterday
add a comment |
I suppose you could use newlisp
, such as
newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'
and vary parameters as desired.
I'm pretty sure you could use perl
or other interpreters as well, though newlisp
is quite small and it can be compiled into a static program as well.
The above example will make the program connect to localhost
port 3456
, and issue the line go for it
on the socket, then it will exit. Goto the newlisp home site for more details.
JRE ?? Not sure where you got that one from.
– Ralph Rönnquist
yesterday
newlisp.org/index.cgi?Downloads shows a JRE dependency to me?
– gertvdijk
yesterday
It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.
– Ralph Rönnquist
yesterday
Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!
– gertvdijk
yesterday
Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.
– Ralph Rönnquist
yesterday
add a comment |
I suppose you could use newlisp
, such as
newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'
and vary parameters as desired.
I'm pretty sure you could use perl
or other interpreters as well, though newlisp
is quite small and it can be compiled into a static program as well.
The above example will make the program connect to localhost
port 3456
, and issue the line go for it
on the socket, then it will exit. Goto the newlisp home site for more details.
I suppose you could use newlisp
, such as
newlisp -e '(write-line (net-connect "localhost" 3456) "go for it")'
and vary parameters as desired.
I'm pretty sure you could use perl
or other interpreters as well, though newlisp
is quite small and it can be compiled into a static program as well.
The above example will make the program connect to localhost
port 3456
, and issue the line go for it
on the socket, then it will exit. Goto the newlisp home site for more details.
answered yesterday
Ralph RönnquistRalph Rönnquist
2,69759
2,69759
JRE ?? Not sure where you got that one from.
– Ralph Rönnquist
yesterday
newlisp.org/index.cgi?Downloads shows a JRE dependency to me?
– gertvdijk
yesterday
It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.
– Ralph Rönnquist
yesterday
Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!
– gertvdijk
yesterday
Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.
– Ralph Rönnquist
yesterday
add a comment |
JRE ?? Not sure where you got that one from.
– Ralph Rönnquist
yesterday
newlisp.org/index.cgi?Downloads shows a JRE dependency to me?
– gertvdijk
yesterday
It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.
– Ralph Rönnquist
yesterday
Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!
– gertvdijk
yesterday
Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.
– Ralph Rönnquist
yesterday
JRE ?? Not sure where you got that one from.
– Ralph Rönnquist
yesterday
JRE ?? Not sure where you got that one from.
– Ralph Rönnquist
yesterday
newlisp.org/index.cgi?Downloads shows a JRE dependency to me?
– gertvdijk
yesterday
newlisp.org/index.cgi?Downloads shows a JRE dependency to me?
– gertvdijk
yesterday
It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.
– Ralph Rönnquist
yesterday
It's a bit of bad advertising, I think :) Of course one can run newlisp with a Java process as a front-end, if it's too hard to do terminal interaction. But that is newlisp plus a front-end. You don't want/need a front-end, esp. as you want to execute only the command line script.
– Ralph Rönnquist
yesterday
Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!
– gertvdijk
yesterday
Oh, yeah I see it now. The JRE is for development. I see that the actual binary is quite lightweight, thanks. Still, some libreadline I see I don't have in the container, but yeah, close enough for an answer!
– gertvdijk
yesterday
Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.
– Ralph Rönnquist
yesterday
Yes. Normal build requires libreadline, libffi and libdl. Though it's quite easy to build a binary without needing any of them (and lose the related functionality of course). Ask at newlispfanclub.alh.net if you need.
– Ralph Rönnquist
yesterday
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508688%2fhow-to-send-literal-string-over-tcp-netcat-socat-like-but-provided-by-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
If you haven't got a shell, what are you expecting to run your command ?
– X Tian
yesterday
you must have somekind of shell if you can run netcat inside your docker. Don't you have access to
busybox echo
orbusybox cat
commands ?– Kiwy
yesterday
@XTian Uhm, you can run commands without a shell! In fact, that's what best practice in containerized environments. E.g.
ENTRYPOINT ["/bin/sh", "-c", "mycommand"]
is unnecessary, just doENTRYPOINT ["mycommand"]
. Also more generally, when processes spawn other processes, you don't want to invoke a full shell, see e.g.man 2 execve
.– gertvdijk
yesterday
1
Please read your question you need to use
|
to execute your command, pipe is part of the shell so you either need a shell/bash/zsh to execute your command either you develop a module tonc
to allow the use of a file as an argument. So if you have a busybox inside you can usebusybox sh
. Distroless is oriented toward application execution so you could either use a python application to do what you want stackoverflow.com/q/1908878/1195001 or use an other docker image as it seems this one doesn't fulfil your goal.– Kiwy
yesterday
2
So you have some restriction on the collection of programs available in your docker environment, and you want someone to guess which of those programs can do the work of reading from a socket and writing to it, and also spawning some other program. It would then help if you then tell which programs you do have rather then telling some you don't have.
– Ralph Rönnquist
yesterday