I need to implement a Nagios Plugin with Bash and check domain expiration date in real time with Whois (most of the domains are .com.ar but not all of them).

In my script has the next code:

WHOIS_DATE=`wget -O - 'https://www.whois.com/whois/'$DOMAIN | grep 'expire' | awk '{print $2}'`
CURRENT_DATE=$(date +%s)
EXPIRE_DATE=$(date --date=$WHOIS_DATE+%s)

With $DAYS variable I can monitor the expiration date of the domain. My issue resides in that the first time the script run, the whois data not found and forces me to open a web browser, paste the URL: https://www.whois.com/whois/google.com.ar to enable it the first time and then the next executions of the sctipt runs well.

I tried with Wget and Curl but without success.


Running your Wget command outside of your script shows this output:

wget -O - 'https://www.whois.com/whois/google.com.ar' | grep 'expire' | awk '{print $2}'
--2019-10-31 15:23:38--  https://www.whois.com/whois/google.com.ar
Resolving www.whois.com (www.whois.com)...
Connecting to www.whois.com (www.whois.com)||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘STDOUT’

-                       [ <=>                ]  46.82K  --.-KB/s    in 0.03s   

2019-10-31 15:23:39 (1.55 MB/s) - written to stdout [47939]

While that progress status stuff is not harmful, I find it confusing for debugging a task like this. Instead, run the same command but with the -q (aka: quiet) parameter set an he output is cleaner; notice the date is the output:

wget -q -O - 'https://www.whois.com/whois/google.com.ar' | grep 'expire' | awk '{print $2}'

That said, the output is cleaner but it seems like there is some DNS resolution stuff on your side. So instead, why not use the whois that is running from the shell like this:

whois 'google.com.ar' | grep 'expire' | awk '{print $2}'

Cleaner and faster and no need to involve an HTTP call with Wget.

|improve this answer|||||
  • @JakeGould other thing, the output of whois in my server is: This TLD has no whois server, but you can access the whois database at http://www.nic.ar/ – lozanotux Oct 31 '19 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.