-1
i=$(cat /etc/icinga/devices.d/xlcdw/full)

if IP in grep -q $i /etc/icinga/devices.d/xlcdw/xlcdw-endpoints.cfg;
    echo "Already configured"
  else
    echo $IP
fi

I'm trying to see whether the hosts I have already configured in the .cfg file are present in the file named 'full.' Of course the above code doesn't even run. I'm grepping for their IP addresses.

  • 3
    the comm command can do what you are looking for. – Tim Kennedy Apr 17 '17 at 19:36
  • 1
    strings are not in both files - how that? – RomanPerekhrest Apr 17 '17 at 19:38
  • Thanks, but that's not going to work. the file "full" is one IP address per line. The .cfg file contains all kinds of alphabetic text in addition to IP addresses. – user189395 Apr 17 '17 at 19:39
  • I need to iterate over the 'full' file to see if the IPs inside it (one per line) are also in the .cfg file. – user189395 Apr 17 '17 at 19:42
  • Here is one entry of hundreds in the .cfg file: define host { host_name JAJA-HDX use generic-host alias JAJAStamfordHarbor02-006 address 192.168.10.9 hostgroups jaja-hdx8k register 1 } – user189395 Apr 17 '17 at 19:52
1

I take your pieces of information out of the comments:

the file "full" is one IP address per line. The .cfg file contains all kinds of alphabetic text in addition to IP addresses.

and

I need to iterate over the 'full' file to see if the IPs inside it (one per line) are also in the .cfg file

So you want to iterate, which your script does not.

Try with a for loop:

for IP in $(cat /etc/icinga/devices.d/xlcdw/full); do
  if [[ `grep -c $IP /etc/icinga/devices.d/xlcdw/xlcdw-endpoints.cfg` > 0 ]]; then
    echo $IP already configured
  else
    echo $IP missing
  fi
done

Adapt that to your needs (which I don't fully understand)

  • @user189395 Did this work for you? Is there still an open issue as you left the question in unanswered state? – Philippos May 1 '17 at 10:25

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.