Bash Scripting Series — Level 5
Bash Scripting Series — Level 5: TCP Port Monitoring and Change Detection Introduction In Level 4, we learned how to identify running processes using pgrep and display their Process IDs (PIDs). In Level 5, we will use Bash to monitor a different aspect of a Linux system: its listening TCP ports. A listening port can indicate that an application or service is waiting for incoming connections. Monitoring these ports helps system administrators identify changes in the services running on a machine. For example, if you start a web server, it may begin listening on port 8000 . If the server stops, that listening endpoint should disappear from the system's socket listing. In this lesson, we will build a script that records listening TCP endpoints, saves timestamped scan results, compares each new scan with the previous one, and reports additions or removals. We will also improve the original script's error handling and make its results easier to compare. 1. The Original Script #!/bi...