Skip to main content
Solved

Script Help to Write Part of Computer Name as txt File

  • July 24, 2018
  • 2 replies
  • 34 views

dennisnardi
Forum|alt.badge.img+15

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

Best answer by mm2270

#!/bin/bash

CompName=$(scutil --get ComputerName)
UserName=$(echo "$CompName" | awk -F'-' '{print $2}')

echo "$UserName"

2 replies

mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • Answer
  • July 24, 2018
#!/bin/bash

CompName=$(scutil --get ComputerName)
UserName=$(echo "$CompName" | awk -F'-' '{print $2}')

echo "$UserName"

dennisnardi
Forum|alt.badge.img+15
  • Author
  • Jamf Heroes
  • July 24, 2018

Ah, duh! Worked perfect, Thank you!