SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    little bit of unix command line scripting help please

    i want to write a simple quick and dirty script that makes a whois query and emails me when the word SUSPENDED doesn't occur in the output. i've got the basics done. i just need to know how to join two bits i've got together so that the second bit gets run conditionally.

    apparently:
    whois thedomain.com | grep -q SUSPENDED
    returns 0 if the word SUSPENDED is part of the output of the whois lookup.

    and
    message.txt | sendmail myemail@address.com

    sends me an email containing the contents of the file message.txt (can't work out how to send a message from the command line rather than a file pointed to from the command line but that really doesn't matter)

    so, how can i conditionally run 'message.txt | sendmail myemail@address.com' based on the response from 'whois thedomain.com | grep -q SUSPENDED' somehow in a script?

    having done the script i'm going to have it trigerred every day by a cron job.

    i'm using mac os x 10.3 so therefore unix.

    thanks.

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The variable $? holds the return value of the last run command , so you can compare it to 0 to see if the script ran properly.

  3. #3
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    thanks. how do you say:

    if( $? != 0 ) message.txt | sendmail myemail@address.com

    in unix/bash/sh/whatever langauge?

  4. #4
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    whois thedomain.com | grep -q SUSPENDED
    
    if [ $? == 0 ]
    then
       message.txt | sendmail myemail@address.com
    fi
    should do the trick for you

  5. #5
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    excellent, i'll give that a go. thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •