Skip to main content
Question

Script - Send email on USB connect

  • January 28, 2015
  • 4 replies
  • 24 views

Forum|alt.badge.img+8

So we're in a situation where we need to setup a headless mac mini in a hospital environment that triggers an email to myself whenever a device is connected via USB so that I can remotely restore a backup to the iOS devices via configurator...does anyone know what such a script would look like? I have no clue where to even start.

4 replies

Forum|alt.badge.img+13
  • Contributor
  • January 28, 2015

I'm thinking that if you create a LaunchDaemon to listen to the /Volumes/ folder, then run a script to perform: [code]diskutil info UNTITLED/ | awk '/Protocol: / {print $2}'[/code] If the result is "USB", then send an email. Should be plenty of bash/python examples to send emails... and Lingon can help with the "Listen" part for /Volumes/

- Justin


Forum|alt.badge.img+8
  • Author
  • Contributor
  • January 28, 2015

The problem with that is that iOS devices don't show up in Volumes. Im not sure where they would show up as connected devices.


Forum|alt.badge.img+16
  • Honored Contributor
  • January 28, 2015

usbmuxd handles iOS communication directly, it never actually mounts as a connected device.


davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • January 28, 2015

Not sure if there is a possible trigger for it, but (assuming it's an iPad) you can use:

system_profiler SPUSBDataType | grep -c iPad

The number returned would be the number of iPads connected to the USB bus.

If there isn't a reliable monitoring method you could have the script run on a regular schedule (something like every 15 minutes).

Regarding the email part, you could use sendMail, details on this are available here: http://www.amsys.co.uk/2014/blog/get-sendemail-working-yosemite-and-mavericks/#.VMlzFV6sVDw.

Alternatively you could see if you could leverage a smart group with Casper's built-in email notification system. You might need to write the value using the API though.