I wrote a small bash script to check if a website is up or not (using isup.me). It works currently (in terminal I call “sh isup.sh stackoverflow.com”). What I’d like to be able to do is call “sh isup.sh stackoverflow.com someother.site” (two arguments) and loop through the output for each argument.
Here is my code:
#!/bin/bash
theSite=$1
curl isup.me/$theSite | grep 'just' | sed s'/<a href="//' | sed s'/" class="domain">//' | sed s'/<\/a>//' | sed s"/http:\/\/$theSite//" | sed s'/<\/span>//'
Another (noncritical) question I have is: can I get rid of the “% Total % Received % Xferd Average Speed Time Time Time Current” bit of the curl function?
curlaccepts multiple URLs, so you just need to build up the list and execute a single command. You can do this pretty simply with a parameter expansion. As an aside, you don’t need to use all those pipes. You can modify the entire thing with a single gsed or awk command. Here’s how I would write it: