Quick "host is up" #commandline #email #net
Using ping(8) to determine whether a host on the local network is up is easy, but a bit slow - especially if what you are doing is checking whether it makes sense to ask the jukebox what song is playing, so you can add an X-Now-Playing: header to the email/article you are composing.
So I went hunting for someting quicker, and came up with this little script, using nmap(1):
#!/bin/sh
CHECK=$1
nmap -PS --max-retries 1 --max-rtt-timeout 20ms --host-timeout 20ms $CHECK | grep --quiet 'Host is up'
RET=$?
if [ $RET = 0 ]; then
echo "UP"
else
echo "DOWN"
fi
exit $RET
Works nicely.
Add comment
How to comment, in excruciating detail…
To avoid spam many websites make you fill out a CAPTCHA, or log in via an account at a corporation such as Twitter, Facebook, Google or even Microsoft GitHub.
I have chosen to use a more old school method of spam prevention.
To post a comment here, you need to:
- Configure a newsreader¹ to connect to the server
- Open the newsgroup called
¹ Such as Thunderbird, Pan, slrn, tin or Gnus (part of Emacs).koldfront.dkon port1119using nntps (nntp over TLS).lantern.koldfrontand post a follow up to the article.Or, you can fill in this form: