Skip to content

Instantly share code, notes, and snippets.

@frdmn

frdmn/README.md

Last active Jan 22, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.