Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A minimal reimplementation of my Python script that renames computers using a Google sheet as a data source.
#!/bin/zsh
# Replace with the ID of your Google Sheet
DOCUMENT_ID="XXX"
SHEET="https://docs.google.com/spreadsheets/d/${DOCUMENT_ID}/edit#gid=0/export?format=csv&id=${DOCUMENT_ID}&gid=0"
/usr/bin/curl -L "${SHEET}" -o /tmp/serial-sheet.csv
/usr/local/bin/jamf setComputerName -fromFile /tmp/serial-sheet.csv
@AllWorkAndNoPlay
Copy link

curl 'https://docs.google.com/spreadsheets/d/DOCUMENTID/export?exportFormat=csv' | grep moved | cut -d "=" -f2-3 | cut -d ">" -f1 | xargs curl -o /tmp/serial-sheet.csv
/usr/local/bin/jamf setComputerName -fromFile /tmp/serial-sheet.csv

@haircut
Copy link
Author

haircut commented Nov 9, 2022

curl 'https://docs.google.com/spreadsheets/d/DOCUMENTID/export?exportFormat=csv' | grep moved | cut -d "=" -f2-3 | cut -d ">" -f1 | xargs curl -o /tmp/serial-sheet.csv
/usr/local/bin/jamf setComputerName -fromFile /tmp/serial-sheet.csv

@AllWorkAndNoPlay can you provide any context here to this comment?

@AllWorkAndNoPlay
Copy link

AllWorkAndNoPlay commented Nov 9, 2022

When I run
/usr/bin/curl -L "${SHEET}" -o /tmp/serial-sheet.csv
with the correct URL, serial-sheet.csv would contain a HTML re-direct page.

The solution for me, was to pull the redirect page, extract the DL url from the re-direct page, and then download the file as CSV using the URL supplied by redirect page.

curl 'https://docs.google.com/spreadsheets/d/DOCUMENTID/export?exportFormat=csv' | grep moved | cut -d "=" -f2-3 | cut -d ">" -f1 | xargs curl -o /tmp/serial-sheet.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment