When it comes to scripting I'd say I'm mediocre compared to most folks so I need some help really nailing down a DO loop which I don't really use very often.
Purpose of the script: We use ARD to remote into machines so we populate ARD Field #1 on our machines to with the asset tag number that applies to the machine; found on a sticker on the bottom of the laptop. We're looking at moving over to DEP and I'll need a way for the user to enter the asset tag number for us since we, as techs, are no longer doing since we're not building the machine any longer.
I'd like for the script to basically not exit until the user has entered an integer into Cocoa Dialog field that is appearing on screen. It's mostly working but it's definitely not pretty and the pop-ups are not appearing in the order I'd like every single time.
1#!/bin/bash23## Global Variables4CD="/Applications/Utilities/CocoaDialog.app/Contents/MacOS/CocoaDialog"5jamfHelper='/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper'6icon='/Users/Shared/icon.png'78## Global functions9enterTag()10{11tag=`"${CD}" standard-inputbox --title "Asset Tag Number Required" --informative-text "Please enter the asset tag number of your computer" --text "Your asset tag can be found on the bottom of your laptop." --float --no-cancel | tail -1`1213if [[ $tag =~ ^-?[0-9]+$ ]]; then14 intCheck="0"15else16 "${jamfHelper}" -windowType utility -icon "$icon" -title "Incorrect Asset Tag Entered" -description "Letters are not allowed in your asset tag. Please re-enter your asset tag using only numbers" -button1 "OK" -defaultButton 117 intCheck="2"18fi19}2021## Run the function22enterTag23echo "pre-loop"2425while [[ $intCheck == "2" ]]; do26 enterTag27 echo "first do loop"28done2930tagConfirm=`"${CD}" msgbox --title "Asset Tag Confirmation" --informative-text <<EOF "You said you're asset tag is: $tag. 31Is that correct?" EOF --button1 "Yes" --button2 "No" --string-ouput`3233while [ $tagConfirm == "2" ]; do34 echo "second do loop"35 enterTag36 tagConfirm=`"${CD}" msgbox --title "Asset Tag Confirmation" --informative-text <<EOF "You said you're asset tag is: $tag. 37Is that correct?" EOF --button1 "Yes" --button2 "No" --string-ouput`3839 while [ "$intCheck" = "2" ]; do40 echo "third do loop"41 enterTag42 tagConfirm=`"${CD}" msgbox --title "Asset Tag Confirmation" --informative-text <<EOF "You said you're asset tag is: $tag. 43Is that correct?" EOF --button1 "Yes" --button2 "No" --string-ouput`44 done45done4647#/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -computerinfo -set1 -1 $tag
Any help would be greatly appreciated!
Thanks!
Chris