Firstly thanks for taking the time to read this thread.
I am trying to write a script that will serve as a post install script for 30 machines in a room & set up their static ip addresses, host names etc.
Currently I have the script for getting the mac address and then searching a tab delimited text file.
the text file is as follows:
MAC_ADDRESS IP_ADDRESS HOST_NAME
The applescript is as follows:
(*Declarations*)
(*set stuff for main page*)
set _subnet to "255.255.0.0"
set _router to "*"
set _dns to "*"
set _domain to "*"
(*set stuff for proxies page*)
set _proxy to "127.0.0.1"
set _proxyport to "8080"
(*Get mac address*)
try
set _mac to paragraph 1 of (do shell script ("ifconfig |grep ether -A 1|grep -w active -B 1|grep ether |awk 'BEGIN { FS=" & "\" \" " & " ;} {" & "
" & " printf( $2 ); }'")) as string
on error
display dialog "Could not determine Mac Address"
end try
(*Resolve mac address to IP form file*)
if (offset of _mac in (read alias "Macintosh HD:ip.txt")) = 0 then
display dialog "MAC Address Not Found In Text File"
else
display dialog "Found! " & _mac
end if
What I want to do is when the mac address is found in the text file is set a couple of variables set _ip to … & set _name to …
unfortunately i can’t work out how to say get the next section on the same line one tab along.
Unless your text file is huge, you could read it all in as a variable and then use a repeat loop to test one paragraph at a time for the MAC address you want, grab the whole paragraph and exit the repeat when you find it. Use AppleScript’s text item delimiters to parse the line with tab as the delimiter to get a list of the three elements.
To get all the MAC addresses a machine might have:
set MAC_1 to do shell script "ifconfig en0 | grep ether | cut -c 8-24"
set MAC_2 to do shell script "ifconfig en1 | grep ether | cut -c 8-24"
set airport_MAC_add to do shell script "ifconfig en1 | grep ether | cut -c 8-24"
return {ethernet_MAC_add_1:MAC_1, ethernet_MAC_add_2:MAC_2, airport_MAC_add:airport_MAC_add}
set example to {"test 1", "test 2", "test 3", "test 4", "test 5", "test 6"}
repeat with i from 1 to (count example) by 3
set thisMAC to item i of example
set thisIP to item (i + 1) of example
set thisHost to item (i + 2) of example
log {thisMAC, thisIP, thisHost}
end repeat