For debugging purposes, it can sometimes be useful to write the results of a command executed at a given time lapse. You can easily monitor a command by using the watch command.
By default a watch command is only displaying result, and you have to be in front of to see the results. If you want to write them in a file with a timestamp, you can easily do it by using this command that combines a watch command with tee:
# watch -t -n 1 "(date '+TIME:%H:%M:%S' ; netstat -np | egrep -i *:443) | tee -a /tmp/logfilewatch"
You can now open your file /tmp/logfilewatch and see the results you just got!
For example, here is what you could get with my previous command, checking all the connections on port TCP 443:
TIME:22:24:22 tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1722/apache2 TIME:22:24:23 tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1722/apache2 TIME:22:24:35 tcp 0 0 192.168.100.250:443 12.34.56.78:27911 TIME_WAIT - TIME:22:24:36 tcp 0 0 192.168.100.250:443 12.34.56.78:27911 TIME_WAIT - TIME:22:24:37 tcp 0 0 192.168.100.250:443 12.34.56.78:27911 TIME_WAIT - TIME:22:24:38 tcp 0 0 192.168.100.250:443 12.34.56.78:27911 TIME_WAIT - TIME:22:24:39 tcp 0 0 192.168.100.250:443 12.34.56.78:27916 SYN_RECV - tcp 0 0 192.168.100.250:443 12.34.56.78:27911 TIME_WAIT - TIME:22:24:41 tcp 0 0 192.168.100.250:443 12.34.56.78:27916 ESTABLISHED 16810/apache2 tcp 0 0 192.168.100.250:443 12.34.56.78:27911 TIME_WAIT - TIME:22:24:42 tcp 0 0 192.168.100.250:443 12.34.56.78:27916 ESTABLISHED 16810/apache2 tcp 0 0 192.168.100.250:443 12.34.56.78:27911 TIME_WAIT -