Solved

shell and socket

Posted on 2001-06-27
9
361 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
 
LVL 1

Expert Comment

by:zmanz
ID: 6297889
:)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now