Skip to content

Instantly share code, notes, and snippets.

@opragel
Last active January 20, 2016 21:36
Show Gist options
  • Save opragel/964c7e5d776f5186ef98 to your computer and use it in GitHub Desktop.
Save opragel/964c7e5d776f5186ef98 to your computer and use it in GitHub Desktop.
collect_sysdiagnose_logs_for_current_user.sh
#!/bin/bash
currentUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
computerHostname=$(hostname)
dateTime=$(date +%F_%H-%M-%S)
archiveName="$computerHostname-logs.$dateTime"
outputDirectory="/Users/$currentUser/Desktop/"
expect <<- DONE
set timeout -1
spawn sysdiagnose -b -d -f "$outputDirectory" -A "$archiveName"
expect "*?ontinue*"
send -- "\r"
expect eof
DONE
chown "$currentUser:staff" "$outputDirectory$archiveName.tar.gz"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment