Solved

shell and socket

Posted on 2001-06-27
9
376 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Avoiding pop-up when starting a linux scrip/shell 5 109
understanding folder structure inside an rpm 2 74
yum remove leaves empty directories 1 93
bash file 10 49
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 fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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