Skip to main content
Question

Rename computer using Google Sheet


Show first post

69 replies

Forum|alt.badge.img+11
  • Valued Contributor
  • 135 replies
  • May 13, 2022
kwoodard wrote:

You can. I did the echo's so I could follow which step things were on and it helped with troubleshooting.


I am assuming its one of these correct?

echo $JAMF_STATUS echo $JAMF_MESSAGE

Forum|alt.badge.img+9
  • Contributor
  • 40 replies
  • May 19, 2022

Thank you for this script!


Forum|alt.badge.img+7
  • Contributor
  • 26 replies
  • June 29, 2022

Has anyone else had a problem when exporting the Google Spreadsheet to a CSV?  I went to /var/tmp/ and when I open the csv file, it seems to error out on cell B9 and then stops adding the rest of the records.  The first 6 computers appear, but the computer name appears to always break at cell B9.  I've tried a brand new spreadsheet and moving that record to the bottom of the list, but it error still occurs on B9.


Forum|alt.badge.img+7
  • Valued Contributor
  • 89 replies
  • June 29, 2022

It may be a format error. I had an issue when copying and pasting the info but everything worked when I typed it in.


Forum|alt.badge.img+7
  • Contributor
  • 26 replies
  • June 29, 2022

OK. I figured it out thanks to iTecNote. In Parameter 4, I had to remove the edit#gid=0 from the end of the URL and add export?exportFormat=csv

 

 

Now it's successfully downloading the csv file.  I also am using a completely new Google Spreadsheet.  For some reason, when I went to change the Document ID back to the old one, it would fail again.  I was able to copy and paste all the data into the new one and confirmed the csv gets the correct number of records.


JKingsnorth
Forum|alt.badge.img+7
  • Valued Contributor
  • 51 replies
  • July 7, 2022

Has anyone had trouble getting this to work recently? I have been using this rename-computer.py for several years now without changing any of the script or policy and all of a sudden it is returning errors. It's acting as if the sheet isn't downloading but the link I'm using downloads the csv file just fine so I'm not sure where the error would be. 

 


JKingsnorth
Forum|alt.badge.img+7
  • Valued Contributor
  • 51 replies
  • July 7, 2022
JKingsnorth wrote:

Has anyone had trouble getting this to work recently? I have been using this rename-computer.py for several years now without changing any of the script or policy and all of a sudden it is returning errors. It's acting as if the sheet isn't downloading but the link I'm using downloads the csv file just fine so I'm not sure where the error would be. 

 


I tried @dwaterbury 's fix above and am still having the same issue. New sheet, new format, same error.


kwoodard
Forum|alt.badge.img+12
  • Author
  • Valued Contributor
  • 280 replies
  • July 7, 2022
JKingsnorth wrote:

Has anyone had trouble getting this to work recently? I have been using this rename-computer.py for several years now without changing any of the script or policy and all of a sudden it is returning errors. It's acting as if the sheet isn't downloading but the link I'm using downloads the csv file just fine so I'm not sure where the error would be. 

 


Try using the script I shared above that’s written in bash, instead of python. 


JKingsnorth
Forum|alt.badge.img+7
  • Valued Contributor
  • 51 replies
  • July 7, 2022
kwoodard wrote:

Try using the script I shared above that’s written in bash, instead of python. 


Switching to Bash worked. No idea why Python stopped working all of a sudden today, I use this nearly daily.


Forum|alt.badge.img+7
  • Contributor
  • 26 replies
  • July 7, 2022

Sorry that I wasn't fully clear in my earlier post.  I had switched over to the Bash script because starting around Mac OSX 12.3, it appears Apple has removed Python 2.


JKingsnorth
Forum|alt.badge.img+7
  • Valued Contributor
  • 51 replies
  • June 21, 2023

Here we are again... Another update another issue (thanks Apple). Still using this script in Bash and it works on Intel, M1 and M2 Macs prior to 2023 models. The script is failing on new M2 2023 MBP 14's.

This is the error its returning but only on these new devices:

"There was an error. You must specify a computer name. Use the -name flag ERROR: Unable to set computer name without local CSV file."

 

I've used this method for years. I have the spreadsheet filled out and the script has been working until today.

 


kwoodard
Forum|alt.badge.img+12
  • Author
  • Valued Contributor
  • 280 replies
  • June 21, 2023
JKingsnorth wrote:

Here we are again... Another update another issue (thanks Apple). Still using this script in Bash and it works on Intel, M1 and M2 Macs prior to 2023 models. The script is failing on new M2 2023 MBP 14's.

This is the error its returning but only on these new devices:

"There was an error. You must specify a computer name. Use the -name flag ERROR: Unable to set computer name without local CSV file."

 

I've used this method for years. I have the spreadsheet filled out and the script has been working until today.

 


I wonder if the script needs to be written in zsh? How big is the document getting that you have your name file? I know mine is about 1mb, so it downloads pretty quickly. Perhaps yours is too large and the script is running before the csv file is downloaded?


JKingsnorth
Forum|alt.badge.img+7
  • Valued Contributor
  • 51 replies
  • June 21, 2023
kwoodard wrote:

I wonder if the script needs to be written in zsh? How big is the document getting that you have your name file? I know mine is about 1mb, so it downloads pretty quickly. Perhaps yours is too large and the script is running before the csv file is downloaded?


It cant be too big, it's only 160 lines. I currently have a 10 second wait time for download on the script but the error it returns starts off saying that the file downloaded successfully to a /var location.


kwoodard
Forum|alt.badge.img+12
  • Author
  • Valued Contributor
  • 280 replies
  • June 21, 2023
JKingsnorth wrote:

It cant be too big, it's only 160 lines. I currently have a 10 second wait time for download on the script but the error it returns starts off saying that the file downloaded successfully to a /var location.


Have you tried opening the folder where the CSV is downloading to and watching it to see if the file actually is downloaded? And if it is downloaded, is there any data in it?


JKingsnorth
Forum|alt.badge.img+7
  • Valued Contributor
  • 51 replies
  • June 26, 2023
kwoodard wrote:

Have you tried opening the folder where the CSV is downloading to and watching it to see if the file actually is downloaded? And if it is downloaded, is there any data in it?


Got this working. Wasn't actually an Apple update that killed it but rather a Google update that affected the security/sharing settings on the Google Sheet we used.


kwoodard
Forum|alt.badge.img+12
  • Author
  • Valued Contributor
  • 280 replies
  • June 26, 2023
JKingsnorth wrote:

Got this working. Wasn't actually an Apple update that killed it but rather a Google update that affected the security/sharing settings on the Google Sheet we used.


That's good to know.


Forum|alt.badge.img+4
  • Contributor
  • 11 replies
  • June 27, 2023
JKingsnorth wrote:

Got this working. Wasn't actually an Apple update that killed it but rather a Google update that affected the security/sharing settings on the Google Sheet we used.


Thanks for the heads up.  I bumped into this issue earlier in the year and made the adjustment without thinking to update the JN thread. :)


Forum|alt.badge.img+1
  • New Contributor
  • 3 replies
  • August 21, 2023
JKingsnorth wrote:

Here we are again... Another update another issue (thanks Apple). Still using this script in Bash and it works on Intel, M1 and M2 Macs prior to 2023 models. The script is failing on new M2 2023 MBP 14's.

This is the error its returning but only on these new devices:

"There was an error. You must specify a computer name. Use the -name flag ERROR: Unable to set computer name without local CSV file."

 

I've used this method for years. I have the spreadsheet filled out and the script has been working until today.

 


Hi @kwoodard 

The bash script was working until 10 days ago. Also have been using it for a lonng time.

Please tell me you have a fix...           that would make my day!

Thanks


kwoodard
Forum|alt.badge.img+12
  • Author
  • Valued Contributor
  • 280 replies
  • August 21, 2023
Francoislb wrote:

Hi @kwoodard 

The bash script was working until 10 days ago. Also have been using it for a lonng time.

Please tell me you have a fix...           that would make my day!

Thanks


I'm not sure. Mine is still working.


Forum|alt.badge.img+1
  • New Contributor
  • 3 replies
  • August 21, 2023

You mentioned a Google update changed something in Google security, but cannot see what changed. I do have the exact error when the policy runs:  "You must specify a computer name. Use -name flag.

It was working a week ago.


Forum|alt.badge.img+1
  • New Contributor
  • 6 replies
  • September 18, 2023

I have the same issue with M2 mac minis.  The same error insisting on -name where this script has -fromFile.


Forum|alt.badge.img+1
  • New Contributor
  • 3 replies
  • September 18, 2023

Check the share permissions. I "fixed it" by switching to the following: 

Someone, something rolled it back to Restricted. 


Forum|alt.badge.img+1
  • New Contributor
  • 6 replies
  • September 18, 2023
Francoislb wrote:

Check the share permissions. I "fixed it" by switching to the following: 

Someone, something rolled it back to Restricted. 


That's still the same on mine.  No joy.  It's still asking for -name


Forum|alt.badge.img+1
  • New Contributor
  • 6 replies
  • September 18, 2023

Script result: waiting 10 seconds
finished waiting Successfully downloaded https://drive.google.com/file/d/109bL3ee--------------ijkr-dnu/view?usp=drive_link to /var/tmp/computernames.csv 1 There was an error. You must specify a computer name. Use the -name flag ERROR: Unable to set computer name without local CSV file.


Forum|alt.badge.img+4
  • Contributor
  • 11 replies
  • September 18, 2023
maestromarv wrote:

That's still the same on mine.  No joy.  It's still asking for -name


We are only running Airs, but we have both M1 and M2 and they are working just fine.  Be sure you are not using the Python script as that version of Python is no longer functional in Mac OS

 

#!/bin/bash

CSV_PATH='/var/tmp/Tech Inventory based Laptop Naming Sheet - Sheet1.csv'
CSV_URL=$4

# Downloads a remote CSV file to CSV_PATH
function download_csv() {
# -s flag to turn off curl's output
# -f flag to have catchable exit status
# -L for url link
# -o for output to filename
# double quotes around CSV_URL becuase curl prefers the url in quotes
curl -s -f -L -o "$CSV_PATH" ""$CSV_URL""
CURL_STATUS=$?

echo "waiting 10 seconds"
sleep 10
echo "finished waiting"

if [[ $CURL_STATUS -eq 0 ]]; then
echo "Successfully downloaded $CSV_URL to $CSV_PATH"
elif [[ $CURL_STATUS -eq 3 ]]; then
# File I/O error
echo "ERROR: Unable to write file at $CSV_PATH"
exit 1
else
# Download error
echo "ERROR: Unable to open URL at $CSV_URL"
exit 1
fi
}

# Renames a computer using the Jamf binary and local CSV at CSV_PATH
function rename_computer() {
/usr/local/bin/jamf help
JAMF_MESSAGE=$(sudo /usr/local/bin/jamf setComputerName -fromFile "$CSV_PATH")
JAMF_STATUS=$?
echo $JAMF_STATUS
echo $JAMF_MESSAGE
if [[ JAMF_STATUS -eq 0 ]]; then
RENAME=$(echo $JAMF_MESSAGE | awk 'END{print $NF}')
echo $RENAME
if [[ -n RENAME ]]; then
# on success the jamf binary reports 'Set Computer Name to XXX'
# so we split the phrase and return the last element
echo "SUCCESS: Set computer name to $RENAME"
else
echo "ERROR: Unable to set computer name. Is this device in the remote CSV file?"
exit 1
fi
else
echo "ERROR: Unable to set computer name without local CSV file."
exit 1
fi

}

if [[ -z $4 ]]; then
echo 'ERROR: You must provide the URL of a remote CSV file.'
exit 1
fi

CSV_URL=$4

#call download_csv
download_csv

#call rename_computer
rename_computer


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