Last active
August 29, 2015 14:27
-
-
Save pmbuko/445c56e5d63ec332eb98 to your computer and use it in GitHub Desktop.
Revisions
-
pmbuko revised this gist
Aug 13, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ #!/bin/bash # This script will change the hostname of a Mac to a dot-separated version # of the full name of the most-commonly-logged-in user with a local home. # Give a list of usernames to ignore, separated by spaces ignore_list=( root admin administrator bukowinskip ) -
pmbuko revised this gist
Aug 13, 2015 . 1 changed file with 16 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ # most-commonly-logged-in user with a local home found under /Users. # Give a list of usernames to ignore, separated by spaces ignore_list=( root admin administrator bukowinskip ) # Get a list of usernames sorted by login frequency, limited to the last 100 logins login_list=$(last -t console -100 | \ @@ -13,29 +13,28 @@ login_list=$(last -t console -100 | \ # Simple function to check if user is in ignore list ignore_match () { local i for i in "${ignore_list[@]}"; do [[ "$i" == "$1" ]] && return 0; done return 1 } # This block will run through login_list and operate on only the first username in the list # that happens to have a local home. for u in $login_list; do # Proceed if user is not in ignore_list and has a local home if ! ignore_match "$u" && [ -d "/Users/${u}" ]; then # Get user's full name, substituting periods for spaces dotted_name=$(dscl -plist . read "/Users/$u" RealName | \ awk 'BEGIN { OFS="." } /string/{gsub("<.?string>","");$1 = $1;print}') # Set the hostnames (comment echo lines and uncomment scutil lines after testing) echo "This script would have changed the compter name to '$dotted_name'" echo "Uncomment the three 'scutil' lines in the script to make it actually change it." #scutil --set ComputerName $dotted_name #scutil --set LocalHostName $dotted_name #scutil --set HostName $dotted_name # skip all further names in login_list break fi done -
pmbuko revised this gist
Aug 13, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ ignore_match () { # that happens to have a local home. for u in $login_list; do # proceed only if user shouldn't be ignored if ! ignore_match "$u"; then # Proceed only if the user has a local home in the expected location if [ -d "/Users/${u}" ]; then dotted_name=$(dscl . read "/Users/$u" RealName | awk 'BEGIN { OFS="." } !/:/{$1 = $1;print}') -
pmbuko revised this gist
Aug 13, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ login_list=$(last -t console -100 | \ sort | uniq -c | sort -r | awk '{print $2}') # Simple function to check if user is in ignore list ignore_match () { local e for e in "${ignore_list[@]}"; do [[ "$e" == "$1" ]] && return 0; done return 1 @@ -22,7 +22,7 @@ ignore_user () { # that happens to have a local home. for u in $login_list; do # proceed only if user shouldn't be ignored if [ ! $(ignore_match "$u") ]; then # Proceed only if the user has a local home in the expected location if [ -d "/Users/${u}" ]; then dotted_name=$(dscl . read "/Users/$u" RealName | awk 'BEGIN { OFS="." } !/:/{$1 = $1;print}') -
pmbuko revised this gist
Aug 13, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ login_list=$(last -t console -100 | \ # Simple function to check if user is in ignore list ignore_user () { local e for e in "${ignore_list[@]}"; do [[ "$e" == "$1" ]] && return 0; done return 1 } -
pmbuko revised this gist
Aug 13, 2015 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,26 +3,26 @@ # This script will change the hostname of a Mac to the full name of the # most-commonly-logged-in user with a local home found under /Users. # Give a list of usernames to ignore, separated by spaces ignore_list=( root admin administrator ) # Get a list of usernames sorted by login frequency, limited to the last 100 logins login_list=$(last -t console -100 | \ awk '/console/{print $1}' | \ sort | uniq -c | sort -r | awk '{print $2}') # Simple function to check if user is in ignore list ignore_user () { local e for e in "${ignoreUsers[@]}"; do [[ "$e" == "$1" ]] && return 0; done return 1 } # This block will run through login_list and operate on only the first username in the list # that happens to have a local home. for u in $login_list; do # proceed only if user shouldn't be ignored if [ ! $(ignore_user "$u") ]; then # Proceed only if the user has a local home in the expected location if [ -d "/Users/${u}" ]; then dotted_name=$(dscl . read "/Users/$u" RealName | awk 'BEGIN { OFS="." } !/:/{$1 = $1;print}') -
pmbuko revised this gist
Aug 13, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ login_list=$(last -t console -100 | \ sort | uniq -c | sort -r | awk '{print $2}') # Simple function to check if item is in an array ignore_user () { local e for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done return 1 @@ -22,11 +22,11 @@ shouldIgnore () { # that happens to have a local home. for u in $login_list; do # proceed only if user is not in ignore list if [ ! $(ignore_user "$u" "${ignoreUsers[@]}") ]; then # Proceed only if the user has a local home in the expected location if [ -d "/Users/${u}" ]; then dotted_name=$(dscl . read "/Users/$u" RealName | awk 'BEGIN { OFS="." } !/:/{$1 = $1;print}') # Now set the hostnames echo "This script would have changed the compter name to '$dotted_name'" echo "Uncomment the three 'scutil' lines in the script to make it actually change it." -
pmbuko revised this gist
Aug 13, 2015 . 1 changed file with 25 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,26 +3,39 @@ # This script will change the hostname of a Mac to the full name of the # most-commonly-logged-in user with a local home found under /Users. # Give a list of usernames to ignore (leave a space between each username) ignore_list=( root administrator ) # Get a list of usernames sorted by login frequency, limited to the last 100 logins login_list=$(last -t console -100 | \ awk '/console/{print $1}' | \ sort | uniq -c | sort -r | awk '{print $2}') # Simple function to check if item is in an array shouldIgnore () { local e for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done return 1 } # This block will run through login_list and operate on only the first username in the list # that happens to have a local home. for u in $login_list; do # proceed only if user is not in ignore list if [ ! shouldIgnore "$u" "${ignoreUsers[@]}"]; then # Proceed only if the user has a local home in the expected location if [ -d "/Users/${u}" ]; then dotted_name=$(dscl . read "/Users/$u" RealName | awk 'BEGIN { OFS="." } !/:/{$1 = $1;print}') # Now set the hostnames echo "This script would have changed the compter name to '$dotted_name'" echo "Uncomment the three 'scutil' lines in the script to make it actually change it." #scutil --set ComputerName $dotted_name #scutil --set LocalHostName $dotted_name #scutil --set HostName $dotted_name # skip all further names in login_list break fi fi done -
pmbuko revised this gist
Aug 12, 2015 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,6 @@ login_list=$(last -t console -100 | \ awk '/console/ && !/root/{print $1}' | \ sort | uniq -c | sort -r | awk '{print $2}') # This block will run through login_list and operate on only the first username in the list # that happens to have a local home. for u in $login_list; do -
pmbuko revised this gist
Aug 12, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ # This script will change the hostname of a Mac to the full name of the # most-commonly-logged-in user with a local home found under /Users. # Get a list of usernames sorted by login frequency, limited to the last 100 logins login_list=$(last -t console -100 | \ awk '/console/ && !/root/{print $1}' | \ sort | uniq -c | sort -r | awk '{print $2}') -
pmbuko revised this gist
Aug 12, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ login_list=$(last -t console -100 | \ sort | uniq -c | sort -r | awk '{print $2}') # This block will run through login_list and operate on only the first username in the list # that happens to have a local home. for u in $login_list; do # Proceed only if the user has a local home in the expected location -
pmbuko created this gist
Aug 12, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ #!/bin/bash # This script will change the hostname of a Mac to the full name of the # most-commonly-logged-in user with a local home found under /Users. # Get a list of usernames sorted by frequency, limited to the last 100 logins login_list=$(last -t console -100 | \ awk '/console/ && !/root/{print $1}' | \ sort | uniq -c | sort -r | awk '{print $2}') # This block will run through login_list and operate on only the first name in the list # that happens to have a local home. for u in $login_list; do # Proceed only if the user has a local home in the expected location if [ -d "/Users/${u}" ]; then dotted_name=$(dscl . read "/Users/$u" RealName | awk 'BEGIN { OFS="." } !/:/{$1 = $1;print}') # Now set the hostnames echo "This script would have changed the compter name to '$dotted_name'" echo "Uncomment the three 'scutil' lines in the script to make it actually change it." #scutil --set ComputerName $dotted_name #scutil --set LocalHostName $dotted_name #scutil --set HostName $dotted_name # skip all further names in login_list break fi done