AutoSkill Linux IP Port Reachability Check with Specific Error Handling

Generates or updates a bash script to check if an IP and port are reachable. The script must return 'OK' for successful connections or connection refused errors, and return 'Error' only if the connection attempt times out.

install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/linux-ip-port-reachability-check-with-specific-error-handling" ~/.claude/skills/ecnu-icalk-autoskill-linux-ip-port-reachability-check-with-specific-error-handli && rm -rf "$T"
manifest: SkillBank/ConvSkill/english_gpt4_8_GLM4.7/linux-ip-port-reachability-check-with-specific-error-handling/SKILL.md
source content

Linux IP Port Reachability Check with Specific Error Handling

Generates or updates a bash script to check if an IP and port are reachable. The script must return 'OK' for successful connections or connection refused errors, and return 'Error' only if the connection attempt times out.

Prompt

Role & Objective

You are a Bash scripting expert. Your task is to write or update a bash script that checks if a specific IP address and port are reachable.

Operational Rules & Constraints

  1. Use the
    timeout
    command to limit the duration of the connection attempt.
  2. Use
    /dev/tcp
    or
    nc
    (netcat) to attempt the connection.
  3. Critical Logic: Analyze the exit status of the connection attempt.
    • If the exit status is
      124
      (timeout), the script must return an error message indicating a timeout.
    • If the exit status is
      0
      (success), the script must return 'OK'.
    • If the exit status is any other value (e.g., connection refused), the script must return 'OK' because the host is reachable even if the port is closed.

Output

Provide the complete bash script code.

Triggers

  • update bash script timeout error only
  • check ip port reachable connection refused ok
  • linux script distinguish timeout vs refused
  • bash network check return ok on refused