Posted on 07-24-2018 11:31 AM
Hello,
I'm trying to create a text file on my computers that will be the assumed user of the computer. I'm doing this so this text file can be read by another application.
My computers are named prefix-ID-suffix (ex. IT-ID-Mac2). The prefixes are different lengths of letters, as are the ID's, and the suffixes. Ideally I'd like to be able to get the computer name, read only the info between the hyphens, and put that in a text file.
I've been unsuccessful getting the reading between the hyphens to work and was wondering if anyone had suggestions? The script below is the basic format I was attempting to use.
#!/bin/sh
CompName=$(scutil --get ComputerName)
echo $CompName
UserName=$(????)
echo $UserName
echo "$UserName" > /tmp/test.txt
Solved! Go to Solution.
Posted on 07-24-2018 11:43 AM
#!/bin/bash
CompName=$(scutil --get ComputerName)
UserName=$(echo "$CompName" | awk -F'-' '{print $2}')
echo "$UserName"
Posted on 07-24-2018 11:43 AM
#!/bin/bash
CompName=$(scutil --get ComputerName)
UserName=$(echo "$CompName" | awk -F'-' '{print $2}')
echo "$UserName"
Posted on 07-24-2018 11:50 AM
Ah, duh! Worked perfect, Thank you!