LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices



Closed Thread
 
Search this Thread
Old 03-11-2010, 05:38 PM   #1
vouser
LQ Newbie
 
Registered: Mar 2010
Posts: 10

Rep: Reputation: 0
Writing to and reading from a socket from bash script.


Hello all.
Here the description of the issue I am having.
I am writing a bash test script which reads lines from a file, builds ISO messages, sends them to a server, reads the response with response code and reports the result of the test to a file or on the screen.

The message that I need to send is 94 characters long.
Here's the portion of a code that I initially wrote:

###############################################

#~ Open socket.
exec 3<>/dev/tcp/172.26.0.25/9991

#~ Send msg.
echo "$msg_out" >&3 # OK but adds EOL character which confuses the server.


#~ Receive msg.
read -r msg_in <&3
echo "msg_in: $msg_in"

###############################################

It works OK with the "echoserver".
However, it does not on a real server.
The symptom is that the program is blocked on "read" statement.
One of the facts that is confirmed by server people is that the message received by a server is actually 95 bytes long.

So, based on this information I have 2 questions:

1. Is there any other way to do what I do in line "echo "$msg_out" >&3" to avoid End Of Line character?
2. Am I using the correct way to read from socket? "read -r msg_in <&3".

Thanks for your help,
vouser.
 
Old 03-11-2010, 09:37 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Duplicate thread reported and taken of zero reply list.
 
Old 03-12-2010, 11:07 PM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate and the question fits best in the Programming forum where you posted your first question.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a bash script s_b Linux - Newbie 7 10-08-2008 01:32 PM
Reading and writing a file with bash XeroXer Linux - Newbie 7 06-02-2008 09:08 AM
bash: create a descriptor reading/writing from/to different files? Thinking Programming 0 04-19-2006 04:28 PM
BASH script Ė reading and writing variables to a separate file morrolan Programming 10 09-20-2005 08:45 AM
writing bash script ankitgdit Programming 4 08-19-2003 07:47 AM


All times are GMT -5. The time now is 03:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration