Skip to main content
added 4 characters in body
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

A number of thoughts

  1. Your script is (presumably) running as root, so that netstat -Wpet can run and sudo -u ${user} operation is simplified.

  2. Using a reverse connection such as ssh -R 20202:localhost:22 centralserver I cannot get a port and user combination from the netstat | grep | grep | cut ... line.

    netstat -Wpet | grep "ESTABLISHED"  | grep sshd:
    tcp   0   36   centralserver:ssh   client:37226   ESTABLISHED   root   238622975   15198/sshd:   roaima
    

    As a result I can't usefully test possible changes to your script. What are you expecting to see here?

  3. You have a race condition, such that if a second file is changed after the inotifywait has completed it may not get propagated to all your target systems until another file has been changed.

    A fix for this might be to listen for events from a single instance of inotifywait and run the set of rsync transfers on each event. However, depending on the frequency of updates this might saturate your clients' network connections

  4. You have an omission problem, in that a client connecting after a set of changes will not receive those changes until the next file change. If the updates are this critical you need to consider some way of updating the client copy immediately they have connected

  5. You should consider a timeout for each ssh/rsync to the client so that if they disconnect while you're attempting a transfer you don't end up blocking everyone else

  6. Given a snippet of bash code such as this, you may be able to replace cut statements with variable manipulation (%, #, and / operators)

     while read -r proto recvq sendq localaddrport foreignaddrport state user inode pidprogram name
     do
         localaddr="${localaddrport%:*}" localport="${localaddport#*localaddrport#*:}"
         foreignaddr="${foreignaddrport%:*}" foreignport="${foreignaddport#*foreignaddrport#*:}"
         pid="${pidprogram%/*}" program="${pidprogram#*/}"; program="${program%:}"
    
         echo "Foreign address = $foreignaddr and port = $foreignport"
         echo "PID = $pid, program = $program"
         echo "Name = $name"
    
     done < <(netstat -Wpet | grep '\<localhost.localdomain:.*\<ESTABLISHED\>.*/sshd:')
    
  7. If we could see expected output of your netstat command it might be possible to use awk to simplify the line processing

A number of thoughts

  1. Your script is (presumably) running as root, so that netstat -Wpet can run and sudo -u ${user} operation is simplified.

  2. Using a reverse connection such as ssh -R 20202:localhost:22 centralserver I cannot get a port and user combination from the netstat | grep | grep | cut ... line.

    netstat -Wpet | grep "ESTABLISHED"  | grep sshd:
    tcp   0   36   centralserver:ssh   client:37226   ESTABLISHED   root   238622975   15198/sshd:   roaima
    

    As a result I can't usefully test possible changes to your script. What are you expecting to see here?

  3. You have a race condition, such that if a second file is changed after the inotifywait has completed it may not get propagated to all your target systems until another file has been changed.

    A fix for this might be to listen for events from a single instance of inotifywait and run the set of rsync transfers on each event. However, depending on the frequency of updates this might saturate your clients' network connections

  4. You have an omission problem, in that a client connecting after a set of changes will not receive those changes until the next file change. If the updates are this critical you need to consider some way of updating the client copy immediately they have connected

  5. You should consider a timeout for each ssh/rsync to the client so that if they disconnect while you're attempting a transfer you don't end up blocking everyone else

  6. Given a snippet of bash code such as this, you may be able to replace cut statements with variable manipulation (%, #, and / operators)

     while read -r proto recvq sendq localaddrport foreignaddrport state user inode pidprogram name
     do
         localaddr="${localaddrport%:*}" localport="${localaddport#*:}
         foreignaddr="${foreignaddrport%:*}" foreignport="${foreignaddport#*:}
         pid="${pidprogram%/*}" program="${pidprogram#*/}"; program="${program%:}"
    
         echo "Foreign address = $foreignaddr and port = $foreignport"
         echo "PID = $pid, program = $program"
         echo "Name = $name"
    
     done < <(netstat -Wpet | grep '\<localhost.localdomain:.*\<ESTABLISHED\>.*/sshd:')
    
  7. If we could see expected output of your netstat command it might be possible to use awk to simplify the line processing

A number of thoughts

  1. Your script is (presumably) running as root, so that netstat -Wpet can run and sudo -u ${user} operation is simplified.

  2. Using a reverse connection such as ssh -R 20202:localhost:22 centralserver I cannot get a port and user combination from the netstat | grep | grep | cut ... line.

    netstat -Wpet | grep "ESTABLISHED"  | grep sshd:
    tcp   0   36   centralserver:ssh   client:37226   ESTABLISHED   root   238622975   15198/sshd:   roaima
    

    As a result I can't usefully test possible changes to your script. What are you expecting to see here?

  3. You have a race condition, such that if a second file is changed after the inotifywait has completed it may not get propagated to all your target systems until another file has been changed.

    A fix for this might be to listen for events from a single instance of inotifywait and run the set of rsync transfers on each event. However, depending on the frequency of updates this might saturate your clients' network connections

  4. You have an omission problem, in that a client connecting after a set of changes will not receive those changes until the next file change. If the updates are this critical you need to consider some way of updating the client copy immediately they have connected

  5. You should consider a timeout for each ssh/rsync to the client so that if they disconnect while you're attempting a transfer you don't end up blocking everyone else

  6. Given a snippet of bash code such as this, you may be able to replace cut statements with variable manipulation (%, #, and / operators)

     while read -r proto recvq sendq localaddrport foreignaddrport state user inode pidprogram name
     do
         localaddr="${localaddrport%:*}" localport="${localaddrport#*:}"
         foreignaddr="${foreignaddrport%:*}" foreignport="${foreignaddrport#*:}"
         pid="${pidprogram%/*}" program="${pidprogram#*/}"; program="${program%:}"
    
         echo "Foreign address = $foreignaddr and port = $foreignport"
         echo "PID = $pid, program = $program"
         echo "Name = $name"
    
     done < <(netstat -Wpet | grep '\<localhost.localdomain:.*\<ESTABLISHED\>.*/sshd:')
    
  7. If we could see expected output of your netstat command it might be possible to use awk to simplify the line processing

Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

A number of thoughts

  1. Your script is (presumably) running as root, so that netstat -Wpet can run and sudo -u ${user} operation is simplified.

  2. Using a reverse connection such as ssh -R 20202:localhost:22 centralserver I cannot get a port and user combination from the netstat | grep | grep | cut ... line.

    netstat -Wpet | grep "ESTABLISHED"  | grep sshd:
    tcp   0   36   centralserver:ssh   client:37226   ESTABLISHED   root   238622975   15198/sshd:   roaima
    

    As a result I can't usefully test possible changes to your script. What are you expecting to see here?

  3. You have a race condition, such that if a second file is changed after the inotifywait has completed it may not get propagated to all your target systems until another file has been changed.

    A fix for this might be to listen for events from a single instance of inotifywait and run the set of rsync transfers on each event. However, depending on the frequency of updates this might saturate your clients' network connections

  4. You have an omission problem, in that a client connecting after a set of changes will not receive those changes until the next file change. If the updates are this critical you need to consider some way of updating the client copy immediately they have connected

  5. You should consider a timeout for each ssh/rsync to the client so that if they disconnect while you're attempting a transfer you don't end up blocking everyone else

  6. Given a snippet of bash code such as this, you may be able to replace cut statements with variable manipulation (%, #, and / operators)

     while read -r proto recvq sendq localaddrport foreignaddrport state user inode pidprogram name
     do
         localaddr="${localaddrport%:*}" localport="${localaddport#*:}
         foreignaddr="${foreignaddrport%:*}" foreignport="${foreignaddport#*:}
         pid="${pidprogram%/*}" program="${pidprogram#*/}"; program="${program%:}"
    
         echo "Foreign address = $foreignaddr and port = $foreignport"
         echo "PID = $pid, program = $program"
         echo "Name = $name"
    
     done < <(netstat -Wpet | grep '\<localhost.localdomain:.*\<ESTABLISHED\>.*/sshd:')
    
  7. If we could see expected output of your netstat command it might be possible to use awk to simplify the line processing