Skip to main content

Thought I'd share this, I've set this up as a Self Service item, it relies on the built-in sysdiagnose tool, and then puts together a nice user-friendly e-mail so they can submit their woes to us.



As a side note, the icon I chose is a stack of *actual* logs... you know, like portions of trees... apparently this was somewhat entertaining to some folks here....



Enjoy!



#!/bin/bash

# Set Variables
# Who's the current console user?
LOGGEDIN=`who | grep console | awk '{print $1}'`
# What's the default mail client for the logged in user?
DEFAULTMAIL=`defaults read /Users/$LOGGEDIN/Library/Preferences/com.apple.LaunchServices.plist | perl -e 'while(<>) {push @lines, $_; m~mailto~ and last} $_ = $lines[-2]; s~[^"]+"~~;s~";~~;print'`
# Get the Computer Name
COMPUTER=`hostname`
# The file that sysdiagnose created to add as an attachment
FILE=`ls -ltr /var/tmp | tail -1 | awk '{print $9}'`
# Name of the disk the OS is booted off of for AppleScript to be happy...
BOOTDISK=`diskutil info / | grep "Volume Name" | cut -c 30-50`
# Path on local machine to CocoaDialog
CD="/Path/To/CocoaDialog.app/Contents/MacOS/CocoaDialog"

# Simple expect to get the return for sysdiagnose to run
expect <<- DONE
set timeout -1
spawn sysdiagnose

# Look for prompt
expect "*?ontinue*"
# send blank line (
) to make sure we get back to gui
send -- "
"
expect eof
DONE

# Based on what default mail client the user is using, put everything together in a nice mail for them
if [ "$DEFAULTMAIL" == "com.apple.mail" ];
then

echo "tell application "Mail"
set theContent to ("Included are System Diagnostic logs from the computer ${COMPUTER}. \\r \\r Please include any details about what was going on on your machine that caused you to send us this information. \\r \\r Affected Application: \\r Is the problem reproducable: \\r Steps to reproduce: \\r Expected Results: \\r Actual Results: \\r \\r ")
set theEmail to make new outgoing message with properties {visible:true, subject:"System Diagnostic Logs from ${COMPUTER}", content:theContent}
tell theEmail
make new recipient at end of to recipients with properties {address:"administrator@example.com"}
make new attachment with properties {file name:"$BOOTDISK:var:tmp:$FILE" as alias} at after last paragraph
end tell
end tell" | osascript

elif [ "$DEFAULTMAIL" == "com.microsoft.outlook" ];
then

echo "tell application "Microsoft Outlook"
set theContent to ("Included are System Diagnostic logs from the computer ${COMPUTER}. <br><br> Please include any details about what was going on on your machine that caused you to send us this information. <br><br> Affected Application: <br> Is the problem reproducable: <br> Steps to reproduce: <br> Expected Results: <br> Actual Results: <br><br> ")
set theAttachment to file "$BOOTDISK:var:tmp:$FILE" as alias
set newMessage to make new outgoing message with properties {subject:"System Diagnostic Logs from ${COMPUTER}", content:theContent}
make new recipient at newMessage with properties {email address:{name:"Administrator", address:"administrator@example.com"}}
make new attachment at newMessage with properties {file:"$BOOTDISK:var:tmp:$FILE" as alias}
open newMessage
end tell" | osascript

# Not using Mail or Outlook? Here's the file and what to do with it...
else
$CD ok-msgbox --text "No Acceptable Mail Client Found"
--informative-text "It appears that neither Apple Mail or Microsoft Outlook are being used as your default mail applications. If you wish to send the diagnostic report please send the resulting file to administrator@example.com"
--no-newline --float
logger "No suitable mail client found"

exit 0
fi

Oldie but goodie! In case you want to upload to an smb file share instead:



computername=`scutil --get ComputerName`
logfile=`ls /tmp/ | grep sysdiagnose`

mkdir /tmp/SHARENAME 2>&1
mount -t smbfs //USERNAME:PASSWORD@SERVERNAME/SHARENAME /tmp/SHARENAME

if [ ! -d /tmp/SHARENAME/${computername} ]; then
mkdir /tmp/SHARENAME/${computername}
fi

cp /tmp/${logfile} /tmp/SHARENAME/${computername}/

rm /tmp/${logfile}

umount -t smbfs /tmp/SHARENAME

Andrina: thank you very much for sharing. found your "Getting Users to Do Your Job (Without Them Knowning It) YouTube video.


Hi @jarednichols , I've been using your script above to collect client logs onto an AFP dropbox, with great success -- thanks for this. But, the "jamf mount" command fails for me since I upgraded my JSS to v9.9 -- that's the only change I made at the time. I can still mount the share manually in the Finder just as I'd expect, I just can't "jamf mount" it successfully. The script returns:



Mounting 172.20.1.8
Could not mount distribution point "172.20.1.8"
There was an error mounting the file server at 172.20.1.8. Will attempt again.
Mounting to /Volumes/ClientLogs...
Could not mount distribution point "172.20.1.8"
There was an error mounting the file server at 172.20.1.8. Giving up.
zip I/O error: No such file or directory
zip error: Could not create output file (/Volumes/ClientLogs/2016-04-08-bhwhite.zip)
umount: /Volumes/ClientLogs: not currently mounted



Do you have any advice? Thanks in advance for any suggestions.


@brandon.white and I were able to fix this in our organization by replacing the JAMF mount command with OSX's native mount_afp command:



#!/bin/sh

# Mount the drive
sudo mkdir /Volumes/ClientLogs
mount_afp "afp://172.20.1.8/ClientLogs" /Volumes/ClientLogs

# Send zip file
dateformat=`date +"%Y-%m-%d"`
hostname=`jamf getComputerName | sed -e 's/<computer_name>//' -e 's/</computer_name>//'`

user=`ls -l /dev/console | cut -d " " -f 4`
filename="$dateformat-$hostname.zip"

zip -r /Volumes/ClientLogs/$filename /var/log/ /Library/Logs/ /Users/$user/Library/Logs
umount -f /Volumes/ClientLogs

exit 0

We do something a bit different with the diagnostic output.
We upload them to the JSS in attachments, and then we can grab it from there.
More Info


Sorry to bug you on this old thread...but has anyone had luck to attach multiple attachments in a new message in Outlook by command line?


Reply