Infinite "while" loop subshell loses current date variable

    • Infinite "while" loop subshell loses current date variable

      I have a simple script to log network connectivity to a set of systems.

      However, as expected the date appended to the log never changes because the new variable is lost when the loop starts again. Can someone clue me in on how to get around this issue?


      Shell-Script

      1. #!/bin/bash
      2. LOG=/tmp/netlog
      3. when=`/bin/date`
      4. while true;
      5. do
      6. for server in srv1 srv2 srv3 srv4 srv5;
      7. do
      8. ping -c 1 $server > /dev/null
      9. if [ $? -ne 0 ]; then
      10. echo "$server-DOWN!" $when >> $LOG.$server
      11. else
      12. echo "$server-UP!" $when >> $LOG.$server
      13. fi
      14. done
      15. done
      Display All