Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

shell and socket

hi,

is it possible (like in C) to send some txt i read from a file to a socket with simple shell scripting.

thx
marduk
0
Marduk060400
Asked:
Marduk060400
1 Solution
 
interiotCommented:
Netcat (ftp://coast.cs.purdue.edu/pub/tools/unix/netutils/netcat/nc110.tgz) can be used for this (doc is here:  ftp://coast.cs.purdue.edu/pub/tools/unix/netutils/netcat/README.local).

So then you'd do:

   cat somefile.txt | nc somehost.com 1234

But this is only appropriate if you're focusing on the shell scripting part.  If you're focusing on the C part, I'm sure someone else will have a solution.
0
 
ahoffmannCommented:
I don't know of any shell which has the ability to communicate with sockets directly.
Use a scripting language like perl, tcl, python instead.
0
 
zmanzCommented:
Use inetd.
Here is a simple example if you want the shell server to
listen on port 7777.

1. Create a script called /usr/sbin/junk with the following
   contents and give it the proper permissions:

#!/bin/bash
cat /pathtosomefile/somefile


2. Add the following entry to /etc/inetd.conf and restart
   inetd with a killall -HUP <cr>

7777 stream tcp nowait root /usr/sbin/junk

3. Check it to see if it works.
   telnet hostname 7777 <cr>
   You should see the contents of the file.

If you put an entry in /etc/services you can use the name
of the service that you made instead of the number.

You can basically write any kind of script and turn
it into a server by using inetd.

Other distributions of linux may use something other
that inetd. Some use something called xinetd or something
like that. The fuctionallity should be basically the
same though.



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
zmanzCommented:
:)
0
 
zmanzCommented:
:(
0
 
zmanzCommented:
My answer does work. I tried it. Really.
0
 
zmanzCommented:
                    Use inetd.
                     Here is a simple example if you want the shell server to
                     listen on port 7777.

                     1. Create a script called /usr/sbin/junk with the following
                       contents and give it the proper permissions:

                     #!/bin/bash
                     cat /pathtosomefile/somefile


                     2. Add the following entry to /etc/inetd.conf and restart
                       inetd with a killall -HUP <cr>

                     7777 stream tcp nowait root /usr/sbin/junk

                     3. Check it to see if it works.
                       telnet hostname 7777 <cr>
                       You should see the contents of the file.

                     If you put an entry in /etc/services you can use the name
                     of the service that you made instead of the number.

                     You can basically write any kind of script and turn
                     it into a server by using inetd.

                     Other distributions of linux may use something other
                     that inetd. Some use something called xinetd or something
                     like that. The fuctionallity should be basically the
                     same though.
0
 
SpideyModCommented:
All,
I am unlocking this question in preparation for cleanup.  I will return in 7 days to finalize this question.  Please leave any recommendations for the final state of this question, I will take all recommendations into consideration.  Failing any feedback, I may decide in 7 days to delete or PAQ this question with no refund.  Thanks.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
SpideyModCommented:
PAQ'd

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now