Link to home
Start Free TrialLog in
Avatar of John Sheehy
John SheehyFlag for United States of America

asked on

Using an inventory file in a script

We have many machines 40+ and their names are changing all the time.  We have one host inventory file called HostInv.  That is always updated when machine changes names.

My script currently uses this:
HOSTS="HOST1 HOST2 HOST3......HOST40"

I would like to use the HostInv file instead of always updating the script how would I do this?

HostInv file is located in /h/HostFiles/

Could I do this?
HOSTS="/h/HostFiles/HostInv"

Thanks
John
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

HOSTS=$(cat /h/HostFiles/HostInv)

or

HOSTS=$(</h/HostFiles/HostInv)
Avatar of John Sheehy

ASKER

Now I was just looking at our HostInv and they do add some info the end of the machine name so it looks like this

Test_Platform_Two:OS=SOL10

How do I just have it read before the colon?

Thanks
John
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am going to test it out and will let you know shortly, thank
John
What does the -f1 and -d option do?

Thanks
John
cut is used to cut the lines of a file or a string read from stdin into pieces (fields) -> not to be confused with "cat"!
-f1 means "cut out and display only the first field" and
-d":" defines the colon as the field delimiter (or field separator, if you prefer).
Great solution and provided very quickly.  Explanation on options was great as well.  Had to make two small changes and place a space before and after each quotation.  But other than that it worked as described.

Thanks
John