Find the answer to your Linux question:
Results 1 to 3 of 3
I have this script to update the named.ca and need to check the output to see if two fields match. I want to check if the ANSWER and ADDITIONAL numbers ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2005
    Location
    NC
    Posts
    5

    bash script to update named.ca file;


    I have this script to update the named.ca and need
    to check the output to see if two fields match.

    I want to check if the ANSWER and ADDITIONAL numbers match.

    this is what it should look like.
    this is a whole line of output.

    ;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13
    and sometimes it may look like this.
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 5

    is there a way to check for this in bash?
    and if so how?

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    If the variable line contains a single line of your file then you can do
    Code:
    let a=$(echo $line|sed -rn 's@^;;.*ANSWER: *([0-9]+) *,.*ADDITIONAL: *([0-9]+)@\1-\2@p')
    If the numbers are equal then a will have the value 0.

  3. #3
    Just Joined!
    Join Date
    Jun 2005
    Location
    NC
    Posts
    5

    Wow;

    That done the trick.
    I used grep to get the line of intrest.

    This is what I added to the script.
    Code:
    LINE=$($CAT $ROOT_HINTS_NEW | $GREP ';; flags:*')
    let RECORDS=$(echo $LINE | sed -rn 's@^;;.*ANSWER: *([0-9]+) *,.*ADDITIONAL: *([0-9]+)@\1-\2@p')
    
    if [ $RECORDS -ne 0 ]; then
    	echo "Subject: $ROOT_HINTS update failed. The records dont match."
    	echo
    	exit 1
    fi
    That is some regex.
    There is no way I would have figured that one out.

    Thanks a ton!

Posting Permissions

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