-
-
Save haircut/2a409fffe55ba65aa353642e5697f38b to your computer and use it in GitHub Desktop.
#!/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 |
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?
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
@AllWorkAndNoPlay The script from haircut are downloading the file but exactly how you said. It cames as html.
When I try your command the file will be downloaded but not stored on my computer.
Update: I got it. I've done some mistakes reading and understanding the script from @AllWorkAndNoPlay .
In the end the mistake was to try adding both scripts together and forget to adding the documentID in the URL from @AllWorkAndNoPlay
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