Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

bash sockets

Featured Replies

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

 

  • 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.

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).

 

  • 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.

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

  • 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.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.