Running Linkcheck with a Bash script
In managing a website composed of a few pages, running Linkcheck every few months may be sufficient. If a website includes thousands of pages, it may be more efficient to run Linkcheck for specific directories. This would facilitate examination of the final output of Linkcheck, and revision of broken links.
As shown on the page for Linkcheck usage, the command for running Linkcheck can be lengthy. Typing the whole command with all the options may be cumbersome by itself. To facilitate running of Linkcheck, I recommend using a simple script that includes all the options.
A sample script to run:
bash linkcheck.sh directory_name output_file
The script named linkcheck.sh can be placed in the home directory and its code is listed below.
This script has two variables:
1. The name of the directory to be checked ($1).
2. The name of the output file ($2). The extension ".txt" is already included in the script.
```bash
#!/bin/bash
# $1 is the directory (e.g., Documents)
# $2 is the output filename (e.g., my_report)
linkcheck -e --show-redirects --skip-file skip.txt localhost/$1 > ~/www/linkcheck/$2.txt
After saving the file, if necessary, make the file executable by running
chmod +x linkcheck.sh
This script assumes that skip.txt (described on the previous page) is located in the Home directory. The output of Linkcheck will be written to
~/www/linkcheck/$2.txt
This script makes it easy to run linkcheck without worrying about accuracy of the options of linkcheck already included in the script.