Advertisement
metalx1000

Detect new USB Drives added in the last minute

Apr 7th, 2016
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #created by Kris Occhipinti
  4. #http://filmsbykris.com
  5. #Thu Apr  7 12:44:27 EDT 2016
  6. #GPLv3  http://www.gnu.org/licenses/gpl-3.0.html
  7. #source code http://pastebin.com/CGaDFjcc
  8.  
  9. #colors
  10. blink=`echo -en "\e[5m"`
  11. RED=`echo -en "\e[41m"`
  12. bold=`echo -en "\e[1m"`
  13. DEFAULT=`echo -en "\e[49m"`
  14.  
  15. cat << EOF
  16. This script will detect a new USB drive.
  17. Please make sure that the drive is not plugged in
  18. and press <ENTER> when ready.
  19. EOF
  20. read
  21.  
  22. echo "Please plug the drive in and press <ENTER> when ready"
  23. read
  24. echo "Checking for a new USB Drive"
  25. sleep 1
  26.  
  27. #Check for new USB drives added in the last minute
  28. id="$(find /dev/disk/by-id/usb* -mmin -1 -print|grep -v 'part')"
  29.  
  30. let count=$(find /dev/disk/by-id/usb* -mmin -1 -print|grep -v 'part'|wc -l)
  31.  
  32. if [ "$count" -gt 1 ]
  33. then
  34.   echo "${RED}${blink}${bold}"
  35.   echo 'WARNING!!! More then one Drive detected!!!'
  36.   echo "${DEFAULT}"
  37.   echo "$id"
  38. elif [ "$count" -eq 0 ]
  39. then
  40.   echo "${RED}${blink}${bold}"
  41.   echo 'WARNING!!! No New Drives Detected!!!'
  42.   echo "${DEFAULT}"
  43. else
  44.   echo "$id detected at:"
  45.   readlink -f $id
  46. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement