Introduction
In this project, you will learn how to create a script that can check if a program is running on a specified port and print the full path of the program or "OK" if no program is running.
๐ Preview
## Example
$ cd /home/labex/project
$ sh get.sh 3000
/usr/lib/code-server/lib/node
$ sh get.sh 43000
OK
๐ฏ Tasks
In this project, you will learn:
- How to create a Zsh script
- How to use the
lsof
command to check if a port is in use
- How to use the
ps
command to get the full path of a running program
๐ Achievements
After completing this project, you will be able to:
- Write a script that can identify the program running on a specified port
- Troubleshoot issues related to port conflicts in your development environment
- Automate the process of checking for running programs on specific ports
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"])
linux(("`Linux`")) -.-> linux/TextProcessingGroup(["`Text Processing`"])
linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"])
linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"])
linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"])
linux/BasicSystemCommandsGroup -.-> linux/exit("`Shell Exiting`")
linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`")
linux/BasicSystemCommandsGroup -.-> linux/test("`Condition Testing`")
linux/TextProcessingGroup -.-> linux/sed("`Stream Editing`")
linux/TextProcessingGroup -.-> linux/awk("`Text Processing`")
linux/FileandDirectoryManagementGroup -.-> linux/cd("`Directory Changing`")
linux/SystemInformationandMonitoringGroup -.-> linux/ps("`Process Displaying`")
linux/RemoteAccessandNetworkingGroup -.-> linux/netstat("`Network Monitoring`")
subgraph Lab Skills
linux/exit -.-> lab-301473{{"`Get Program That Satisfies the Condition`"}}
linux/echo -.-> lab-301473{{"`Get Program That Satisfies the Condition`"}}
linux/test -.-> lab-301473{{"`Get Program That Satisfies the Condition`"}}
linux/sed -.-> lab-301473{{"`Get Program That Satisfies the Condition`"}}
linux/awk -.-> lab-301473{{"`Get Program That Satisfies the Condition`"}}
linux/cd -.-> lab-301473{{"`Get Program That Satisfies the Condition`"}}
linux/ps -.-> lab-301473{{"`Get Program That Satisfies the Condition`"}}
linux/netstat -.-> lab-301473{{"`Get Program That Satisfies the Condition`"}}
end