Skip to main content
Solved

Script Help to Write Part of Computer Name as txt File


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.

1#!/bin/sh
2
3CompName=$(scutil --get ComputerName)
4 echo $CompName
5
6UserName=$(????)
7 echo $UserName
8
9echo "$UserName" > /tmp/test.txt

Best answer by mm2270

1#!/bin/bash
2
3CompName=$(scutil --get ComputerName)
4UserName=$(echo "$CompName" | awk -F'-' '{print $2}')
5
6echo "$UserName"
View original
Did this topic help you find an answer to your question?

2 replies

mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 replies
  • Answer
  • July 24, 2018
1#!/bin/bash
2
3CompName=$(scutil --get ComputerName)
4UserName=$(echo "$CompName" | awk -F'-' '{print $2}')
5
6echo "$UserName"

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

Ah, duh! Worked perfect, Thank you!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings