Image: naum/Adobe Stock Must-read developer coverage Have you saw a small downturn in your websites lately, but timing them with a stopwatch is doing you no favors? If you discover this is occurring, you understand you’ll need to report it to management, but you don’t want to enter without actionable information.
After all, a slight decrease in speed now might result in a much larger decrease later. And with the competition continuously improving and evolving, your business can not take a chance that those downturns will turn into a much larger issue.
SEE: Hiring set: Back-end Developer (TechRepublic Premium)
To that end, you should keep a record of your site speeds, so you have the info you require to go to those in power and say, “We have a problem.”
With the help of the curl command, you can piece together a basic bash script that can gather those speeds in a helpful, date-stamped file. I’m going to reveal you exactly how to do that.
What you’ll need to check site speeds
The only things you’ll need for this are a running instance of Linux and a user with sudo privilege. The variation of Linux can be a desktop or a server and can be any distribution you like. I’ll show with Ubuntu Server 22.04, so if you’re using a various distribution, you may have to modify the curl installation command.
That’s it. Let’s get scripting.
How to set up curl
Curl ought to currently be set up on your os. If not, it’s easy to do. Log in to your Linux distribution, open a terminal window and issue the command:
sudo apt-get install curl -y
Keep in mind, if you’re utilizing a various circulation, the setup command will vary, such as sudo dnf install curl -y for RHEL-based distributions.
With curl installed, it’s time to produce our script.
How to develop the web speed test bash script
The script we’ll use is really simple to create utilizing the command:
nano ~/ webtest
Because, paste the following:
curl -s -w ‘Screening Site Reaction Time for:% url_effective n nLookup Time: t t% time_namelookup nConnect Time: t t% nPre-transfer Time: t% nStart-transfer Time: t% time_starttransfer n nTotal Time: t t% n’ -o/ dev/null URL > webspeedtest _”$(date)”
Where URL is the address of the site to be tested.
Here’s the breakdown of the script:
- Lookup time shows the amount of time for a request to receive an action.
- Link time records the time till a TCP connection to a remote server is completed.
- AppCon time records the time required for an SSL communication to procedure.
- Redirect time records the overall time for redirection demands.
- Pre-transfer time records the overall time before file transfer starts.
- Start-transfer time records the quantity of time before the first byte is sent to a remote server.
- Overall time records the time it takes to finish a response.
At the end of the script, we direct the output to the file webspeedtest that adds the date and time to the end of the filename. By doing this, we not just have a file to see the test outcomes of that circumstances, but we have a file for every circumstances the test is run, so you can compare outcomes.
Conserve and close the file.
Offer the script executable outcomes with the command:
chmod u+x ~/ webtest
How to run the test script
To run the test, concern the command:
The script ought to run fairly rapidly and will lead to a file called webspeedtest_DATE, where DATE is the date and time stamp for the run. The output of the script will look something like this:
Evaluating Website Response Time for: URL
Lookup Time: 0.120128
Link Time: 0.177519
Pre-transfer Time: 0.177644
Start-transfer Time: 0.240367
Overall Time: 0.240540 Where URL is the address
you set up in the script. How to automate the test Rather
of needing to keep in mind to run the test daily, let’s utilize cron to automate it. Edit your crontab file with the command: crontab-e At the bottom of your crontab file, include the following to instantly run the test at 8 a.m. every morning: 0 8 * * */ home/USER/webtest Where USER is your Linux username. If you’ve conserved the
script in a various directory site
, ensure to change that course. Conserve and close the crontab file with Ctrl+ X. You can likewise set that test to run
per hour if need be with the line: 0 * * * */ home/USER/webtest The something to keep in mind is that you’ll need to prune those test result files, as they will add up.
A basic test for an important metric And there you have it– an automatic speed test script to evaluate an essential metric
for your websites. If you
need to check more than one site, create a script for each, and include a crontab entry for every single test. Although this does not give you every metric you need, it will definitely keep you apprised of one specific test that can help you comprehend if something is happening with your websites. If you discover they continue to slow down, it’s time to start fixing. Register for TechRepublic’s How To Make Tech Work on YouTube for all the latest tech suggestions for company pros from Jack Wallen. Source