The check_links function performs the following tasks:
- Writes the header for the report, including the current date and time, to the report file.
- Extracts all
hrefvalues (links) from the HTML content of the specified URL usingcurlandsed. - Iterates over each extracted link.
- Checks if the link is absolute or relative:
- If the link is relative, it adds the base URL to form a complete URL.
- Uses
curlto measure the HTTP status code for each link. Thecurlcommand is used with the following options:-o /dev/null: Discards the output.-s: Silent mode, which suppresses progress and error messages.-w "%{http_code}\n": Writes the HTTP status code to the variable.-L: Follows redirects.
- Checks if the HTTP status code is
200. If it is, it appends a message stating the link is valid to the report file. Otherwise, it appends a message stating the link is invalid, along with the HTTP status code. - Prints a message indicating that the report has been saved.