Last active
December 14, 2022 12:04
-
-
Save chornberger-c2c/42c982f1642eafd9490938423a519edc to your computer and use it in GitHub Desktop.
Satellite 6 - list all hosts and their IDs
This file contains hidden or 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/bash | |
usage() { | |
cat <<EOF | |
Usage: $0 -s server -u user -p pass | |
Lists host names and host IDs registered to a Satellite Server in CSV format | |
EOF | |
exit 0 | |
} | |
parseOptions() { | |
[[ $# -eq 0 ]] && usage | |
while getopts ":s:u:p:" opt; do | |
case "${opt}" in | |
s) | |
SERVER=${OPTARG} | |
;; | |
u) | |
USER=${OPTARG} | |
;; | |
p) | |
PASS=${OPTARG} | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
} | |
getHostnameAndId() { | |
curl https://"${SERVER}"/api/v2/hosts \ | |
-k \ | |
--user "${USER}":"${PASS}" \ | |
--header "Content-Type: application/json" \ | |
2>/dev/null | \ | |
jq -r '.results[]|.name + "," + (.id|tostring)' | |
} | |
main() { | |
parseOptions "$@" | |
getHostnameAndId | |
exit 0 | |
} | |
main "$@" || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment