Skip to content

Instantly share code, notes, and snippets.

@frdmn
Last active January 5, 2023 10:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frdmn/5eeebc05c61c7a00450aee8b81be824c to your computer and use it in GitHub Desktop.
Save frdmn/5eeebc05c61c7a00450aee8b81be824c to your computer and use it in GitHub Desktop.
Victor's macOS Client information parser
  1. Download the client-information and move it to /usr/local/bin/client-information:

    wget https://gist.githubusercontent.com/frdmn/5eeebc05c61c7a00450aee8b81be824c/raw/520d3e9ae9ec80710344119e1780939fa843130b/client-information -O /usr/local/bin/client-information
    bash +x /usr/local/bin/client-information
    
  2. Configure the scheduler to periodically run the script:

    wget https://gist.githubusercontent.com/frdmn/5eeebc05c61c7a00450aee8b81be824c/raw/520d3e9ae9ec80710344119e1780939fa843130b/victor.client-information.plist -O ~/Library/LaunchAgents/victor.client-information.plist
    
  3. Enable the LaunchAgent scheduler:

    launchctl load ~/Library/LaunchAgents/victor.client-information.plist
    
#!/usr/bin/env bash
# Create temporary file to store XML/Plist into
temp_file=$(mktemp)
# Write XML to file
system_profiler SPSoftwareDataType -xml > ${temp_file}
# Simple function to search for a specific key within
# the Plist and return it's value
function find_and_return_value {
/usr/libexec/PlistBuddy -c "Print :0:_items:0:${1}" ${temp_file}
}
# Function to check if FileVault is enabled or not
function get_filevault_status {
fdesetup status | grep On > /dev/null 2>&1 && echo "enabled" || echo "disabled"
}
# Parse information and construct JSON
json="""
{
\"os_version\":\"$(find_and_return_value "os_version")\",
\"kernel_version\":\"$(find_and_return_value "kernel_version")\",
\"boot_volume\":\"$(find_and_return_value "boot_volume")\",
\"boot_mode\":\"$(find_and_return_value "boot_mode")\",
\"local_host_name\":\"$(find_and_return_value "local_host_name")\",
\"user_name\":\"$(find_and_return_value "user_name")\",
\"secure_vm\":\"$(find_and_return_value "secure_vm")\",
\"system_integrity\":\"$(find_and_return_value "system_integrity")\",
\"uptime\":\"$(find_and_return_value "uptime")\",
\"filevault\":\"$(get_filevault_status)\"
}
"""
rm ${temp_file}
echo ${json}
exit 0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnableGlobbing</key>
<false/>
<key>Label</key>
<string>victor.client-information</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/usr/local/bin/client-information</string>
</array>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/client-information.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/client-information.log</string>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>10</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
<dict>
<key>Hour</key>
<integer>15</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</array>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment