Keep telnet connection open in background and send output to file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Some background: Working with ash shell (busybox) on an embedded device. From a script, I need to keep a local telnet connection open in the background to monitor the output of a service running locally on the device so I can perform actions based on that output. I do not have expect, script, nc available. To clarify, this service is playing an internet radio stream. It will output the current song information in a telnet session when the track changes, and that is what I need to capture specifically.



How can I keep a persistant telnet session open in the background and using custom file descriptors or named pipes read and/or write to the session? My understanding of the syntax for redirects is lacking at best.



EDIT:
I believe I'm on the right track. Again I'm still unclear about custom FD's and named pipes. Truth be told I'm not sure if I need to open FD 6 for reading AND writing. If anyone wants to clarify this syntax for me or suggest a more efficient or reliable method please do.



mkfifo "INPUTPIPE"
exec 6<> "INPUTPIPE"
telnet "HOST" "PORT" <&6 >> "OUTPUTFILE" &


EDIT AGAIN:



The above has been working well for my needs. Telnet remains persistent in the background, and scripts can now parse the lines output from the telnet session by reading "OUTFILE". I'm hesitant to answer however as I would still like someone with more experience to either demonstrate a "more correct" syntax and/or explain this better than I can.










share|improve this question



















  • 2




    If you don't have netcat (nc) or socat you're going to be fighting a losing battle.
    – roaima
    Sep 25 '17 at 22:14











  • What specifically makes nc better than telnet for this scenario just out of curiosity?
    – sunshine
    Sep 25 '17 at 22:46










  • Look at DJB's ucspi-tcp and related utilities (such as daemontools). Take your time to understand how things are supposed to work together.
    – Satō Katsura
    Sep 26 '17 at 7:42










  • I believe me asking here is an attempt at understanding <3
    – sunshine
    Feb 19 at 8:54














up vote
0
down vote

favorite












Some background: Working with ash shell (busybox) on an embedded device. From a script, I need to keep a local telnet connection open in the background to monitor the output of a service running locally on the device so I can perform actions based on that output. I do not have expect, script, nc available. To clarify, this service is playing an internet radio stream. It will output the current song information in a telnet session when the track changes, and that is what I need to capture specifically.



How can I keep a persistant telnet session open in the background and using custom file descriptors or named pipes read and/or write to the session? My understanding of the syntax for redirects is lacking at best.



EDIT:
I believe I'm on the right track. Again I'm still unclear about custom FD's and named pipes. Truth be told I'm not sure if I need to open FD 6 for reading AND writing. If anyone wants to clarify this syntax for me or suggest a more efficient or reliable method please do.



mkfifo "INPUTPIPE"
exec 6<> "INPUTPIPE"
telnet "HOST" "PORT" <&6 >> "OUTPUTFILE" &


EDIT AGAIN:



The above has been working well for my needs. Telnet remains persistent in the background, and scripts can now parse the lines output from the telnet session by reading "OUTFILE". I'm hesitant to answer however as I would still like someone with more experience to either demonstrate a "more correct" syntax and/or explain this better than I can.










share|improve this question



















  • 2




    If you don't have netcat (nc) or socat you're going to be fighting a losing battle.
    – roaima
    Sep 25 '17 at 22:14











  • What specifically makes nc better than telnet for this scenario just out of curiosity?
    – sunshine
    Sep 25 '17 at 22:46










  • Look at DJB's ucspi-tcp and related utilities (such as daemontools). Take your time to understand how things are supposed to work together.
    – Satō Katsura
    Sep 26 '17 at 7:42










  • I believe me asking here is an attempt at understanding <3
    – sunshine
    Feb 19 at 8:54












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Some background: Working with ash shell (busybox) on an embedded device. From a script, I need to keep a local telnet connection open in the background to monitor the output of a service running locally on the device so I can perform actions based on that output. I do not have expect, script, nc available. To clarify, this service is playing an internet radio stream. It will output the current song information in a telnet session when the track changes, and that is what I need to capture specifically.



How can I keep a persistant telnet session open in the background and using custom file descriptors or named pipes read and/or write to the session? My understanding of the syntax for redirects is lacking at best.



EDIT:
I believe I'm on the right track. Again I'm still unclear about custom FD's and named pipes. Truth be told I'm not sure if I need to open FD 6 for reading AND writing. If anyone wants to clarify this syntax for me or suggest a more efficient or reliable method please do.



mkfifo "INPUTPIPE"
exec 6<> "INPUTPIPE"
telnet "HOST" "PORT" <&6 >> "OUTPUTFILE" &


EDIT AGAIN:



The above has been working well for my needs. Telnet remains persistent in the background, and scripts can now parse the lines output from the telnet session by reading "OUTFILE". I'm hesitant to answer however as I would still like someone with more experience to either demonstrate a "more correct" syntax and/or explain this better than I can.










share|improve this question















Some background: Working with ash shell (busybox) on an embedded device. From a script, I need to keep a local telnet connection open in the background to monitor the output of a service running locally on the device so I can perform actions based on that output. I do not have expect, script, nc available. To clarify, this service is playing an internet radio stream. It will output the current song information in a telnet session when the track changes, and that is what I need to capture specifically.



How can I keep a persistant telnet session open in the background and using custom file descriptors or named pipes read and/or write to the session? My understanding of the syntax for redirects is lacking at best.



EDIT:
I believe I'm on the right track. Again I'm still unclear about custom FD's and named pipes. Truth be told I'm not sure if I need to open FD 6 for reading AND writing. If anyone wants to clarify this syntax for me or suggest a more efficient or reliable method please do.



mkfifo "INPUTPIPE"
exec 6<> "INPUTPIPE"
telnet "HOST" "PORT" <&6 >> "OUTPUTFILE" &


EDIT AGAIN:



The above has been working well for my needs. Telnet remains persistent in the background, and scripts can now parse the lines output from the telnet session by reading "OUTFILE". I'm hesitant to answer however as I would still like someone with more experience to either demonstrate a "more correct" syntax and/or explain this better than I can.







scripting busybox telnet fifo ash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 26 '17 at 18:08

























asked Sep 25 '17 at 22:00









sunshine

64




64







  • 2




    If you don't have netcat (nc) or socat you're going to be fighting a losing battle.
    – roaima
    Sep 25 '17 at 22:14











  • What specifically makes nc better than telnet for this scenario just out of curiosity?
    – sunshine
    Sep 25 '17 at 22:46










  • Look at DJB's ucspi-tcp and related utilities (such as daemontools). Take your time to understand how things are supposed to work together.
    – Satō Katsura
    Sep 26 '17 at 7:42










  • I believe me asking here is an attempt at understanding <3
    – sunshine
    Feb 19 at 8:54












  • 2




    If you don't have netcat (nc) or socat you're going to be fighting a losing battle.
    – roaima
    Sep 25 '17 at 22:14











  • What specifically makes nc better than telnet for this scenario just out of curiosity?
    – sunshine
    Sep 25 '17 at 22:46










  • Look at DJB's ucspi-tcp and related utilities (such as daemontools). Take your time to understand how things are supposed to work together.
    – Satō Katsura
    Sep 26 '17 at 7:42










  • I believe me asking here is an attempt at understanding <3
    – sunshine
    Feb 19 at 8:54







2




2




If you don't have netcat (nc) or socat you're going to be fighting a losing battle.
– roaima
Sep 25 '17 at 22:14





If you don't have netcat (nc) or socat you're going to be fighting a losing battle.
– roaima
Sep 25 '17 at 22:14













What specifically makes nc better than telnet for this scenario just out of curiosity?
– sunshine
Sep 25 '17 at 22:46




What specifically makes nc better than telnet for this scenario just out of curiosity?
– sunshine
Sep 25 '17 at 22:46












Look at DJB's ucspi-tcp and related utilities (such as daemontools). Take your time to understand how things are supposed to work together.
– Satō Katsura
Sep 26 '17 at 7:42




Look at DJB's ucspi-tcp and related utilities (such as daemontools). Take your time to understand how things are supposed to work together.
– Satō Katsura
Sep 26 '17 at 7:42












I believe me asking here is an attempt at understanding <3
– sunshine
Feb 19 at 8:54




I believe me asking here is an attempt at understanding <3
– sunshine
Feb 19 at 8:54















active

oldest

votes











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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394419%2fkeep-telnet-connection-open-in-background-and-send-output-to-file%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394419%2fkeep-telnet-connection-open-in-background-and-send-output-to-file%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?