Pinger.sh: A Simple Script for Checking Server Response Times
hive-186392·@thecrazygm·
0.000 HBDPinger.sh: A Simple Script for Checking Server Response Times
Hey everyone, Today I want to share a simple little shell script that I've found surprisingly useful over the years. A while back, I came across a [post on Reddit](https://www.reddit.com/r/commandline/comments/12tebg1/find_out_fastest_mirrorleast_ping_from_a_list_of/) where someone was asking for an easy way to ping a list of servers to find the one with the fastest response time. I whipped up a quick script to solve the problem, and I've honestly ended up using it far more than I ever expected. I call it `pinger.sh`, and its job is simple: it takes a file full of IP addresses or domain names, pings each one, and gives you a nicely formatted, sorted list of the results from fastest to slowest. It's perfect for a couple of common tasks: - Doing a quick uptime check on a list of your personal servers. - Finding the fastest software mirror or public DNS server from your specific location. #### Examples in Action For instance, I can use it to get a quick status update on my personal servers to make sure everything is running smoothly:  Or, I can use it to quickly find the fastest public DNS resolver from my current location:  #### The Script The script itself is a short and straightforward Bash script. It reads each line from the file you provide, pings the address once, and then uses a powerful `sort | column` pipeline at the end to format everything into a neat, easy-to-read table. ```bash #!/bin/bash # Check if the argument is provided if [ $# -eq 0 ]; then echo "Please provide a filename as an argument." exit 1 fi # Read each line of the file while read -r address; do # setting timeout, piping error # Execute ping; if it fails, skip to the next address result=$(ping -c 1 -W 2 "$address" 2>/dev/null) || continue # Extract the ping time from the result using cut time=$(echo "$result" | grep "time=" | cut -d "=" -f 4) # Print the address and the ping time echo "$address $time" done <"$1" | sort -k 2n | column -t -N "Address,Speed" ``` #### How to Use It 1. Save the code above to a file named `pinger.sh`. 2. Make the script executable from your terminal: `chmod +x pinger.sh` 3. Create a text file (e.g., `servers.txt`) with one IP address or domain name per line. 4. Run the script and pass it your text file as an argument: `./pinger.sh servers.txt` It's a simple tool, but it's a great example of how a small script can solve a common problem in a very elegant way. EDIT: [Github Gist](https://gist.github.com/TheCrazyGM/52e6f57d75b864cbf7b5c56e7baaccd5) As always, Michael Garcia a.k.a. TheCrazyGM
👍 beco132, freecompliments, hetty-rowan, tikki00taffi, wongi, beststart, georgesantana73, hive-140084, pepetoken, fc-curation, fc-rewards, fc-arbitration, indiasierra, indeedly, mmbbot, hdmed, magnacarta, poplar-22, ngwinndave, trovepower, ecoinstant, votehero, voter002, fatman, investegg, we-are-lucky, jacor, dailyspam, trashyomen, tub3r0, noctury, chrisly.social, holdeck2, converter.bonus, moretea, morwhale, coolguy123, guurry123, gurseerat, captaincryptic, alkirua, vrezyy, marynn, vrezion, sieghard1990, whitneyalexx, tengolotodo.leo, timix648, bankrobbery, d-a-d, pepe.voter, claudiavb, itz.inno, murtaza-7868, digi-alt, michael561, cryptoknight12, jozefkrichards, kernelillo, hivedrip, accelerator, morwhalebonus, najat, emsenn0, savvyfrog, techken, morwhaleplus, manclar, bengy, aakom, a-bot, bigmoneyman, dpend.active, sketching, iviaxpow3r, mxm0unite, svanbo, thorlock, mighty-thor, splinterwhale, fonestreet, esmeesmith, draygyn, casimodo, mk992039, partytime.inleo, lisamgentile1961, ijebest, steembasicincome, sbi2, sbi3, sbi4, anikys3reasure, awesomegames007, tdas0, piestrikesback, buildingpies, sbi-tokens, qwertm, briefmarken, sbi5, shauner, sbi6, voxmortis, sbi7, sbi8, noloafing, sneakyninja, netzisde, bububoomt, thedailysneak, babysavage, ravensavage, sbi9, sbi10, sports.power.bot, gamer00, neoxvoter, pixelfan, kiemis, youloseagain, mviews, holovision.stem, learn2code, stem.alfa, codingdefined, calmphoenix, rudy-dj, kasih-sayang, russia-btc, quochuy, rulivyxo, letusbuyhive, mosupholstery, cubapl, pakx, niallon11, carolinawnn, artlover, toohip, dune69, followjohngalt, tiffin, mcsherriff, mes, herman-german, olympicdragon, likedeeler, longhunter, adulruna, deggial, mirroredspork, omra-sky, lrekt01, gadrian, imbartley, logen9f, dstampede, mytechtrail, eforucom, fw206, woelfchen, tydynrain, patience2, ecoinstats, treasure.hoard, thecrazygm.bank, archon-gov, irisworld, pof.archon, abrockman, monsterrerentals, everythingsmgirl, ykretz, rafaelaquino, cryptoniusrex, lolz.byte, tokenpimp, technologix, athunderstruck, pimptoken, pimp.token, pimpdistrict, thepimpdistrict, ydaiznfts2, jaouad2d, dibblers.dabs, denizcakmak, iktisat, travelpic, thecryptopimp, biglove, blockchainyouth, hivehustlers, thatsweeneyguy, joeyarnoldvn, russellstockley, jglake, maddogmike, thepeakstudio, holoferncro, kam5iz, slothlydoesit, slothburn, thelogicaldude, slothbuzz, hivelist, ganjafarmer, magic.byte,