2

I have a script in place which is fixing a serialization issue College wide and I have everything mapped out to how that's all going to work but I'd like to see which computers the script has hit.

I was thinking that I would poll the computer for it's "ComputerName" then output this to a .txt file

scutil --get ComputerName

If comptuer name is "DW1234" then I'd like the script to out put a file to /location/DW1234.txt

I just can't figure out how to take the out put of "scutil --get ComputerName" and copy this to be the name "computername.txt

Is this possible? This would make it easy so we can visually see by name which computers have been his with the script.

codeforester
  • 39,467
  • 16
  • 112
  • 140
Carter
  • 21
  • 2

2 Answers2

0
filename=$(scutil --get ComputerName); touch $filename.txt

Try it and tell me if that is what you want.

0

You could probably write it in a more robust way like this:

if filename=$(scutil --get ComputerName); then
  touch "/location/$filename.txt"
fi

This way, you won't end up creating a '.txt' file in case scutil command is not available or it fails for some reason. Double quotes around the argument to touch ensure that we are immune to scutil returning a string that has white spaces in it.


Related:

codeforester
  • 39,467
  • 16
  • 112
  • 140