0

I'm writing a bash script for inventory information, and i'm attempting to collect data on two seperate version of Red Hat. They have two different types of output for the ifconfig, so i'm simply trying to add an 'if' statement to the already working function. I keep getting an error that says syntax error: unexpected end of file . I assume i'm not closing something somewhere, but I can't seem to see it, though i've probably been looking at it too long. any assistance would be great.

Here is the script

#!/bin/sh
OS_VERSION=`cat /etc/redhat-release  |awk '{print $0}'`
pat=".*Santiago.*"

num=1
        if [[ "$OS_VERSION" =~ $pat ]]; then

                for i in `/sbin/ifconfig -a |grep -i -B 3 "UP" |grep -i "HWaddr"|awk '{print $1}'`
                        do
                                {
                                MacAddress=`/sbin/ifconfig $i |grep -i -B 3 "UP" |grep -i "HWaddr"| awk '{print $NF}'`
                                Ip_Address=`/sbin/ifconfig $i|grep -i "inet addr"|awk '{print $2}'|awk -F: '{print $2}'`
                                echo -n "ethName$num=$i | ethMac$num=\"$MacAddress\" | ethIp$num=\"$Ip_Address\" | "
                                num=$(expr $num+1|bc)
                                }
                         else 
                            echo "Not Santiago, use other script"
done;
echo "";
exit
3
  • 4
    Try shellcheck Commented Aug 30, 2018 at 20:45
  • awk '{print $0}' prints its input unchanged, did you mean $1? Commented Aug 30, 2018 at 20:49
  • @thatotherguy thank you sir, that helped! It got that portion working, now I just have a bunch of other things to get working. much appreciated! Commented Aug 30, 2018 at 21:41

1 Answer 1

1

I see an if...

if [[ "$OS_VERSION" =~ $pat ]]; then

...but no fi. (That is the actual issue behind the error message you get -- the file ends -- unexpectedly -- before that if is closed.)

I see a for - do - else... followed by a done...?!?

It should be:

  • if -- then -- [else] -- fi
  • for -- do -- done.

You got those mixed up quite a bit. Proper indenting would have made that obvious.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.