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
Marduk060400Asked:
Who is Participating?
 
SpideyModConnect With a Mentor Commented:
PAQ'd

SpideyMod
Community Support Moderator @Experts Exchange
0
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.