Skip to content

Instantly share code, notes, and snippets.

@stevewood-tx
Last active December 26, 2021 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevewood-tx/4dba9f36252552dca6b16c43464ab899 to your computer and use it in GitHub Desktop.
Save stevewood-tx/4dba9f36252552dca6b16c43464ab899 to your computer and use it in GitHub Desktop.
Simple Logging in Shell Scripts
#!/bin/zsh
mylogpath=/tmp/mylog
mylog=$mylogpath/myawesomlog-$(date +%Y%m%d-%H%M).log
[[ ! -d ${mylogpath} ]]; mkdir -p $mylogpath
set -xv; exec 1> $mylog 2>&1
... do some stuff ...
# Upload our log using API
jss_user="apifileuploaduser"
jss_pass="MysUPerL33tpAssW0rd"
jss_url="https://jps.mycompany.com"
# get computer serial number to lookup the JSS ID of the computer
serial=$(system_profiler SPHardwareDataType | awk '/Serial\ Number\ \(system\)/ {print $NF}');
# get ID of computer
JSS_ID=$(curl -H "Accept: text/xml" -sfku "${jss_user}:${jss_pass}" "${jss_url}/JSSResource/computers/serialnumber/${serial}/subset/general" | xpath /computer/general/id[1] | awk -F'>|<' '{print $3}')
# upload the log to the comptuer record
curl -sku $jss_user:$jss_pass $jpsURL/JSSResource/fileuploads/computers/id/$JSS_ID -F name=@${mylog} -X POST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment