Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to set up a batch file or cronjob of some sort, using the linux command line, to check the availability of domain names. I will provide the list of domains to check using another file. It must then only do 30 checks per hour, and only if the domain is available, it must add that domain name to a different file. So...

  1. Do I have to create a batch file?
  2. What command must go in the batch file, that will:
    1. move through an existing list of domains
    2. check if those domains are available,
    3. remove that domain from the original list, and
    4. add the available domain to the "available" list.
  3. Repeat this command 20 times every hour

I know exactly how to do this with PHP and cron, but I want to know know if there is a quick way to do this using the "whois" command? It's point (2) that I am stuck on.

share|improve this question
I wrote a script in PHP that does, but I am now looking for a quick way to do this via command line, using the "whois" command. – coderama Jun 6 '12 at 11:02
I will add more precise questions... – coderama Jun 6 '12 at 11:02
( i lost the php script.... ) – coderama Jun 6 '12 at 11:05
To start solve this issue, try reading this link: – Octávio Filipe Gonçalves Jun 6 '12 at 11:17
@RD: Sorry, like you can see in my profile, i help people a lot. But i think, you don't ask for help in a particular issue you have in your code. You want only someone write a software for you, with a list a specifications you mention in your question. I think you can investigate a little bit for solve your problem, and then, if you stuck in your code, ask for help. – Octávio Filipe Gonçalves Jun 6 '12 at 11:27
up vote 6 down vote accepted

That's not too hard.

Check the list of domains domains.txt, and add the domain to available.txt once it's found (by looking at the return value of grep, which is stored in $?).

Then, remove the found domains from domains.txt with sed in-place editing.



lockfile whois-script.lock

while read -r domain; do
  whois $domain | grep -qci "No match"
  if [ $? -ne 0 ]; then
    # found
    echo $domain >> $AVAILABLE
done < $DOMAINS

while read -r domain; do
  sed -i "/$domain/d" $DOMAINS

rm -f whois-script.lock

Note: On BSD sed, you want to use the following command:

sed -i "" "/$domain/d" $DOMAINS

You can save this script and call it from your crontab. Enter

crontab -e

and then add a line like this:

*/2 *   *   *   *   /path/to/ > /dev/null

This will run the script every two minutes (*/2). Make sure to adjust the paths to the domain before.

share|improve this answer
Depending on how often the input file changes you may want to add a lock file to prevent two instances running at the same time to avoid a race condition between checking the domains and removing the entries from the input file. – Bram Jun 6 '12 at 11:48
Good point, especially with two minute checks. You think that makes more sense? (See my update) – slhck Jun 6 '12 at 11:52
I tought of it more as "an excercize for the reader" :) but your updated answer will probably do exactly what the OP requested. I forgot to upvote it before, fixed that now. – Bram Jun 6 '12 at 11:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .