Last active
December 26, 2021 17:58
-
-
Save stevewood-tx/4dba9f36252552dca6b16c43464ab899 to your computer and use it in GitHub Desktop.
Simple Logging in Shell Scripts
This file contains 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 characters
#!/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