April 27, 201016 yr I am trying to understand how to use bash to open a socket and send some data, but so far not too well. Here is the snippet of code I am using: exec 3<> /dev/tcp/$sTCPaddress/$sTCPport echo -e "$sTCPmessage $sNewline" >&3 #read the Reply while read <&3 do echo -n $REPLY >&1 done # close the file descriptor exec 3<&- exec 3>&- sTCPmessage contains some valid text as a string (UNR Status: unRaid OK) sNewline contains \n\r\n\r The server side gets the connection request so I know that sTCPaddress and sTCPport are correct. The server side never fires a data arrival request. so for some reason the echo -e . . . does not seem to be working or ? Any help/advice greatly appreciated
April 27, 201016 yr I am trying to understand how to use bash to open a socket and send some data, but so far not too well. Here's some good reading for you: http://shudder.daemonette.org/source/BashNP-Guide.txt That should keep you busy for awhile!
April 28, 201016 yr Author Thanks, but already read that. I think I basically have it working, send side that is, the problem now is how to retrieve the returned data from the peer. I need to read some more.
April 29, 201016 yr Thanks, but already read that. I think I basically have it working, send side that is, the problem now is how to retrieve the returned data from the peer. I need to read some more. I believe bash sockets are "client only", meaning it can't receive the data (listen to the socket), so you will have to use something else (netcat, for example).
April 29, 201016 yr Author In my particular case I am not interested in a response so that does not bother me. I am sending the command to my HA system so it can announce the issue over the house's audio notification system.
April 29, 201016 yr I am trying to understand how to use bash to open a socket and send some data, but so far not too well. Have a look at how bashmail is talking to servers, that may help you. (attached) bashmail.txt
May 6, 201016 yr Author I am well along with my first major attempt at bash programming. I want my theater PC to be able to : 1) Command the unraid system to go to sleep 2) Spin up or down disks 3) Issue a WOL magic Packet I want the Unraid system to always be monitoring an IP port for instructions from the theater and to be able to report status to the theater on command. I am about 75% there. The communications between the tcpip_listener bash script and the theater is rock solid. You can down either side and everything stays coorect. If the Theater goes off the air, the tcpip_listener probes for it to return every 10 seconds until it does. If the unRaid server goes off the air, the theater waits for it to come back. When a connection is started the unraid side sends to the theater a status giving the name of the array and the number of drives in the array. I will eventaully add which drives are spinning and which are not, and allow the Theater to request status at any time. I have some questions re bash and tcpip which I have coded around but I do not feel is proper. In particular it seems that the bash request for input (read to the tcp device) does not wait but is always satisfied, accepting null input when none is sent by the theater. I need to put a sniffer on the line to make sure that the theater is really sending nothing. I thought that the read would wait for input. It might be because I did not specify a read timeout, but I thought that when I did it still exhibited the same behavior. It is always fun learning new things (at least for me) and once again thanks to all who have helped and I am sure will continue to help.
Archived
This topic is now archived and is closed to further replies.