Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

shell and socket

Posted on 2001-06-27
9
Medium Priority
?
399 Views
Last Modified: 2010-04-21
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
Comment
Question by:Marduk060400
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 3

Expert Comment

by:interiot
ID: 6232003
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6242179
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
 
LVL 1

Expert Comment

by:zmanz
ID: 6289603
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
Independent Software Vendors: 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!

 
LVL 1

Expert Comment

by:zmanz
ID: 6297889
:)
0
 
LVL 1

Expert Comment

by:zmanz
ID: 6300140
:(
0
 
LVL 1

Expert Comment

by:zmanz
ID: 6308241
My answer does work. I tried it. Really.
0
 
LVL 1

Expert Comment

by:zmanz
ID: 6357944
                    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
 

Expert Comment

by:SpideyMod
ID: 8275933
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
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8330181
PAQ'd

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question