Send Email with list of Apps

cholder
New Contributor II

What i want to do is when a machine is done imaging via DEP it sends an email to an account with serial number, user and model. This I have working in a script. I now what to add a list of applications that are installed, when it completes.

I want to run this script first and then attach the file applist.txt


!/bin/bash

get list of all current apps installed

appVersionList=$(mdfind -onlyin /Applications 'kMDItemContentType==com.apple.application-bundle' -attr "kMDItemDisplayName" -attr "kMDItemVersion" | sed 's/^.*kMDItemDisplayName//' | sed 's/kMDItemVersion//g' | tr '=' ' ' | sort >> /tmp/applist.txt)

exit 0


Here is the script for sending the email.


!/bin/bash

sHost=$(networksetup -getcomputername)
theserial="$(ioreg -l | grep IOPlatformSerialNumber | sed -e 's/."(.)"/1/')"

sUser=$(id -F) # this finds system admin as it is running using sudo

user=$(ls -l /dev/console | awk '/ / { print $3 }')
model=$(ioreg -l | awk '/product-name/ { split($0, line, """); printf("%s ", line[4]); }')

echo $sHost

echo $theserial

echo $model

echo $user

mail -s "Apple DEP Image Completed: $sHost" "it@corp.com" <<EOF
DEP imaging done for machine $sHost
Serial: $theserial
User is: $user
Model is: $model
EOF


Anyone know the command lines to do this.

1 REPLY 1

mrben
New Contributor III

Sure, remove the (below) so the list of apps remains in the appVersionList variable. Now copy this line to the email script and you'll be able to do Apps are: $appVersionList.

>> /tmp/applist.txt