Some time has passed since op posted this so that they do not see it, but could help someone else.
Anyway, I studied this problem and I found the following.
The open fd (file descriptors) of the process are listed in the / proc // fd section.
exec 3<>/dev/tcp/localhost/9999 #check if still connected if [ $(ls /proc/$$/fd | grep -w "3") == 3 ]; then #send data echo -e "Some Command\n" >&3 else #perform reconnect exec 3<>/dev/tcp/localhost/9999 fi
This has not been verified, but should be basically in order. There may be some improvements. There is also a window in which fd goes between your check and the letter in fd. However, this applies to all decisions.
source share